[Qt-qml] Navigating a hierarchy of sceens? (was: Re: Best practices, patterns, etc.)

Cornelius Hald hald at icandy.de
Tue Sep 7 16:02:02 CEST 2010


On Mon, 2010-09-06 at 22:29 +0200, henrik.hartz at nokia.com wrote:
> > 2) Lets assume 1) is the recommended approach. My idea is to introduce
> > some QML data components. That way I'm hoping I can easily define the C
> > ++ API.
> > For example, lets say we have a component PersonScreen. This screen can
> > show all informations about a person. To populate such a screen with
> > concrete data we're creating a PersonData component like follows.
> > 
> > ----- Components -----
> > PersonData {
> >  property string firstName
> >  property string lastName
> >  property int birthday // unix timestamp :)
> >  property real weight
> >  property url image
> > }
> > 
> > PersonScreen {
> >  property PersonData data
> >  property color backgroundColor
> >  [...]
> >  Text {
> >    text: data.firstName + " " + data.lastName
> >  }
> >  [...]
> > }
> > 
> > ----- Usage ------
> > ExamplePersonData {
> >  id: exPerson
> >  firstName: "Peter"
> >  lastName: "Jones"
> >  birthday: 123456
> >  weight: 80.12
> >  image: http://example.com/peter.jpg
> > }
> > 
> > PersonScreen {
> >  data: exPerson
> >  backgroundColor: "lightblue"
> > }
> > 
> > Having something like the above, I hope I can create a PersonData C++
> > class and simply replace the QML example data with real data coming from
> > the C++ backend. Does this make sense?
> 
> Yes, and with dummyModel and nativeModel you would use;
> 
> ListView {
> ...
> model: nativeModel==undefined ? dummyModel : nativeModel
> }

I'm stuck here. What I tried to do is to have a definition of a Person
with all attributes it may have and a list of Persons displayed in a
ListView. Now when I click on a Person I want to open the PersonScreen
with that Person.

For this to work I would need a ListModel containing Person items, but I
can't create that. Or can I do something like the following?

ListModel {
  Person {
    firstName: bla
    weight: 123.32
  }
  Person {
    firstName: blub
    weight: 54.22
  }
}

To me it looks like I can only have ListElement items inside a
ListModel. But with ListElements I just have property/value pairs and no
information about the type of the element.

Now, maybe it doesn't matter whether or not that element is a Person as
long as it has the right properties. But then, in my delegate how can I
get the model element that was used to create this element?

Maybe I'm completely of the track here, but how do I create the
navigation through a simple hierarchy of screens? Do I have to pass IDs
between the different screens?

Thanks for your patience and help :)
Conny

P.S. To summarize the problem. How can I navigate screens like this:
List of schools -> List of classes -> List of people
Where the selected element in screen x is the input data for screen x+1.





More information about the Qt-qml mailing list