|  | Home · All Classes · Modules

# QDeclarativeListReference Class Reference
[QtDeclarative module]

The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties. More...

### Methods

- __init__ (self)
- __init__ (self, QObject, str property, QDeclarativeEngine engine = None)
- __init__ (self, QDeclarativeListReference)
- bool append (self, QObject)
- QObject at (self, int)
- bool canAppend (self)
- bool canAt (self)
- bool canClear (self)
- bool canCount (self)
- bool clear (self)
- int count (self)
- bool isValid (self)
- QMetaObject listElementType (self)
- QObject object (self)

## Detailed Description

The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties.

QDeclarativeListReference allows C++ programs to read from, and assign values to a QML list property in a simple and type safe way. A QDeclarativeListReference can be created by passing an object and property name or through a QDeclarativeProperty instance. These two are equivalant:

     QDeclarativeListReference ref1(object, "children");

     QDeclarativeProperty ref2(object, "children");
     QDeclarativeListReference ref2 = qvariant_cast<QDeclarativeListReference>(ref2.read());

Not all QML list properties support all operations. A set of methods, canAppend(), canAt(), canClear() and canCount() allow programs to query whether an operation is supported on a given property.

QML list properties are typesafe. Only QObject's that derive from the correct base class can be assigned to the list. The listElementType() method can be used to query the QMetaObject of the QObject type supported. Attempting to add objects of the incorrect type to a list property will fail.

Like with normal lists, when accessing a list element by index, it is the callers responsibility to ensure that it does not request an out of range element using the count() method before calling at().

## Method Documentation

### QDeclarativeListReference.__init__ (self)

Constructs an invalid instance.

### QDeclarativeListReference.__init__ (self, QObject, str property, QDeclarativeEngine engine = None)

Constructs a QDeclarativeListReference for object's property. If property is not a list property, an invalid QDeclarativeListReference is created. If object is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QDeclarativeListReference instances even after object is deleted.

Passing engine is required to access some QML created list properties. If in doubt, and an engine is available, pass it.

### QDeclarativeListReference.__init__ (self, QDeclarativeListReference)

### bool QDeclarativeListReference.append (self, QObject)

Appends object to the list. Returns true if the operation succeeded, otherwise false.

See also canAppend().

### QObject QDeclarativeListReference.at (self, int)

Returns the list element at index, or 0 if the operation failed.

See also canAt().

### bool QDeclarativeListReference.canAppend (self)

Returns true if the list property can be appended to, otherwise false. Returns false if the reference is invalid.

See also append().

### bool QDeclarativeListReference.canAt (self)

Returns true if the list property can queried by index, otherwise false. Returns false if the reference is invalid.

See also at().

### bool QDeclarativeListReference.canClear (self)

Returns true if the list property can be cleared, otherwise false. Returns false if the reference is invalid.

See also clear().

### bool QDeclarativeListReference.canCount (self)

Returns true if the list property can be queried for its element count, otherwise false. Returns false if the reference is invalid.

See also count().

### bool QDeclarativeListReference.clear (self)

Clears the list. Returns true if the operation succeeded, otherwise false.

See also canClear().

### int QDeclarativeListReference.count (self)

Returns the number of objects in the list, or 0 if the operation failed.

### bool QDeclarativeListReference.isValid (self)

Returns true if the instance refers to a valid list property, otherwise false.

### QMetaObject QDeclarativeListReference.listElementType (self)

Returns the QMetaObject for the elements stored in the list property. Returns 0 if the reference is invalid.

The QMetaObject can be used ahead of time to determine whether a given instance can be added to a list.

### QObject QDeclarativeListReference.object (self)

Returns the list property's object. Returns 0 if the reference is invalid.