Take the 2-minute tour ×

can anyone help my clarify what QML Repeater docs mean firstly saying

“Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parent.”,

and then


Aren't child/parent relationship and ownership the same for visual objects in QML?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Object parent (ownership) and visual parent are not the same in QtQuick. The object parent is set at creation time and is never changed. The visual parent can be changed at any time via the 'parent' property.

The Repeater creates the delegates and sets ownership to itself and the visual parent to its parent. In other words, the Repeater owns the delegates, but leaves the visual presentation to its parent (in most cases, a positioner).

The Qt 5 documentation is being improved in this area. Here is a snippet (the Qt 5 doc snapshot hasn't been updated recently - this is from the source):

There are two separate kinds of parenting in a QML application which uses Qt Quick. The first kind is the ownership-parent (also known as the QObject parent) which determines object lifetime semantics. The second kind is the visual-parent which determines where on the canvas an item is drawn, and also certain properties (for example, opacity applies to visual children).

In almost all cases, the visual-parent is identical to the ownership-parent. See the documentation about the Visual Parentfor more in-depth information on the topic.

Unfortunately the "Visual Parent" topic hasn't been written yet.

share|improve this answer
Ok, so this is obviuosly different from QObject/QWidget behavior? Does your knowlege come from the Qt docs? –  mlvljr Jul 3 '12 at 9:22
Oh, it seems, it will actually make into the docs, as the guys at iRC (based on your nick) hinted :) Still, if there's something more you can share on the topic, it will be very helpful (especially, if it's a doc/mailing list discussion link). –  mlvljr Jul 3 '12 at 13:30
My knowledge comes from being a QML/QtQuick developer ;-) But, the docs are being improved for Qt 5. I've updated the answer above with what little additional info is available in the docs atm. –  MartinJ Jul 4 '12 at 3:19
Thanks, Martin. May be (since the docs have not been written yet), you can point me to the appropriate places within Qt5 source code? –  mlvljr Jul 4 '12 at 10:54
QDeclarativeItem parent property WRITE function is QDeclarativeItem::setParentItem() which calls QGraphicsObject::setParentItem(). The QObject parent is set by the engine in qdeclarativevme.cpp. Search for QDeclarative_setParent_noEvent(). We provide no way to change the QObject parent via QML. –  MartinJ Jul 6 '12 at 6:23

Your Answer


