Pure QML approach for creating reusable business objects

3285
4
Jump to solution
04-05-2016 08:26 PM
HeathcliffRongo
New Contributor III

Based on what I've seen on various sites, the advice seems to be you create your business objects in C++, then expose these to QML. Unfortunately, if we go down that path we lose AppStudio Cloud Make which isn't an option.

Does anyone have a pure QML approach for defining business object types, and instantiating such types from some data source (RDMS, XML, etc.)? Ideally I'd like to be able to plug these into a ListModel, for example, and re-use these across different app projects across an enterprise.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
HannahFerrier
Occasional Contributor III

You can build powerful apps using just QML and JavaScript. And not all QML is visual - to create your own QML component, just use an Item without setting any visual elements. E.g.,

import QtQuick 2.4

Item {

    id: _person

   property string firstName: "Hannah"

   property string lastName: "Ferrier"

}

Once you have created your component, you can save it in a QML file and copy this file into as many different projects as you want. Same with JavaScript - write your code once and then copy the files to be used in different projects.

Further reading: Item QML Type | Qt Quick 5.6

View solution in original post

4 Replies
HannahFerrier
Occasional Contributor III

Heathcliff,

In AppStudio for ArcGIS, you currently have available to you all of the features in the Qt QML API as well as the power of the ArcGIS Runtime and the AppStudio Framework.

What specific functionality are you missing?

You can already populate a ListModel in QML from XML: XmlListModel QML Type | Qt Quick 5.6, or does your project require something more?

Hannah

0 Kudos
HeathcliffRongo
New Contributor III

A bit of a contrived example, but say I have a business type called Person, that has the following attributes: FirstName, LastName, DateOfBirth, Gender. In c# for example, you could implement a POCO like:

class Person {

     string FirstName;

     string LastName;

     date DateOfBirth

     string Gender;

}

My understanding is that everything is visual in QML, so how do a implement a non-visual data structure such as Person. Once defined, the intention would be to use it in other apps that also need to know what a Person type is, and also be able to use it as a model for List, Grid or even custom views.

I guess what I'm trying to say is I want to separate business and UI/presentation layers using pure QML. As mentioned previously, my impression is that you need to use C++ to implement business layer logic, but don't want to go down this path.

0 Kudos
HannahFerrier
Occasional Contributor III

You can build powerful apps using just QML and JavaScript. And not all QML is visual - to create your own QML component, just use an Item without setting any visual elements. E.g.,

import QtQuick 2.4

Item {

    id: _person

   property string firstName: "Hannah"

   property string lastName: "Ferrier"

}

Once you have created your component, you can save it in a QML file and copy this file into as many different projects as you want. Same with JavaScript - write your code once and then copy the files to be used in different projects.

Further reading: Item QML Type | Qt Quick 5.6

HeathcliffRongo
New Contributor III

Thanks Hannah. I had looked at Item initially, but wasn't sure if it was appropriate based on the description saying it was the "base type for all visual items". I'll give that approach a try, cheers.

0 Kudos