A list type contains a list of objects. While not technically a basic type, QML supports lists of object types. When used from QML, the engine automatically appends each value to the list. Items in the list can be accessed by index using the usual listName[index] syntax.
For example, the Item class contains a list property named children that can be used like this:
Item { children: [ Item { id: child1 }, Rectangle { id: child2; width: 200 }, Text { id: child3 } ] Component.onCompleted: { console.log("Width of child rectangle:", children[1].width) } }
child1, child2 and child3 will be added to the children list in the order in which they appear.
List properties can be created as a variant type, or as a list<Type> type, where Type is the type of the object in the list:
Item { property list<Rectangle> rects: [ Rectangle { width: 100; height: 100}, Rectangle { width: 200; height: 200} ] }
A list property can only contain values that match (or are derived from) the specified Type.
While the rects property can be reassigned to a different list value (including an empty list), its individual values cannot be modified. See the variant type documentation for details.
See also QML Basic Types.
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.