Skip to content
This repository
branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 .settings
Octocat-spinner-32 arm
Octocat-spinner-32 assets
Octocat-spinner-32 src
Octocat-spinner-32 translations
Octocat-spinner-32 x86
Octocat-spinner-32 .cproject
Octocat-spinner-32 .project
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README
Octocat-spinner-32 bar-descriptor.xml
Octocat-spinner-32 config.pri
Octocat-spinner-32 icon.png
Octocat-spinner-32 readme.txt
This example shows how to use QDeclarativeComponent to instantiate QML elements dynamically in
C++ code. The created QML elements are added to the parent container of the Repeater.

The Repeater has a "delegate" property of type QDeclarativeComponent*, which specifies the component
used for creating the QML elements. The "model" property specifies how often the element should be
repeated. Apart from using an integer constant here, it is also possible to specify a QVariantList
or a DataModel. For the later case, the variant and the map content of the VariantList and the
DataModel are made available in the created QML elements by setting them as their context property.

The fact that writing "delegate: Label { ... }" in QML creates a QDeclarativeComponent* and not a
Label* is a special behavior of the QML engine. Internally, the QML engine checks if the property
(in this case "delegate") is of type QDeclarativeComponent*, and if so, treats the assignment as a
component assignment, not a item assignment.
The Repeater itself just sees a QDeclarativeComponent*, as that is what it gets passed from the QML
Something went wrong with that request. Please try again.