Extending QML - Object and List Property Types ExampleThis example builds on: The Object and List Property Types example shows how to add object and list properties in QML. This example adds a BirthdayParty element that specifies a birthday party, consisting of a celebrant and a list of guests. People are specified using the People QML type built in the previous example. Declare the BirthdayPartyThe BirthdayParty class is declared like this: The class contains a member to store the celebrant object, and also a QList<Person *> member. In QML, the type of a list properties - and the guests property is a list of people - are all of type QDeclarativeListProperty<T>. QDeclarativeListProperty is simple value type that contains a set of function pointers. QML calls these function pointers whenever it needs to read from, write to or otherwise interact with the list. In addition to concrete lists like the people list used in this example, the use of QDeclarativeListProperty allows for "virtual lists" and other advanced scenarios. Define the BirthdayPartyThe implementation of BirthdayParty property accessors is straight forward. Running the exampleThe main.cpp file in the example includes a simple shell application that loads and runs the QML snippet shown at the beginning of this page. |