Extending QML - Adding Types ExampleThe Adding Types Example shows how to add a new element type, Person, to QML. The Person type can be used from QML like this: Declare the Person classAll QML elements map to C++ types. Here we declare a basic C++ Person class with the two properties we want accessible on the QML type - name and shoeSize. Although in this example we use the same name for the C++ class as the QML element, the C++ class can be named differently, or appear in a namespace. Define the Person classThe Person class implementation is quite basic. The property accessors simply return members of the object instance. The main.cpp file also calls the qmlRegisterType() function to register the Person type with QML as a type in the People library version 1.0, and defines the mapping between the C++ and QML class names. 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. |