Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
.settings
arm
assets
src
translations
x86
.cproject
.project
LICENSE
Makefile
README
Repeater.vcxproj
Repeater.vcxproj.filters
bar-descriptor.xml
config.pri
icon.png
readme.txt
repeater.pro

README

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
engine.
Something went wrong with that request. Please try again.