QQmlListReference#

The QQmlListReference class allows the manipulation of QQmlListProperty properties. More

Synopsis#

Functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

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

QQmlListReference ref1(object, "children");

QQmlProperty ref2(object, "children");
QQmlListReference ref2 = qvariant_cast<QQmlListReference>(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 type-safe. 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() .

class PySide6.QtQml.QQmlListReference#

PySide6.QtQml.QQmlListReference(o, property)

PySide6.QtQml.QQmlListReference(o, property, engine)

Note

This constructor is deprecated.

PySide6.QtQml.QQmlListReference(arg__1)

PySide6.QtQml.QQmlListReference(variant)

PySide6.QtQml.QQmlListReference(variant, engine)

Note

This constructor is deprecated.

Parameters:

Constructs an invalid instance.

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

Use the constructors without QQmlEngine argument instead.

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

The engine is unused.

Constructs a QQmlListReference from a QVariant variant containing a QQmlListProperty . If variant does not contain a list property, an invalid QQmlListReference is created. If the object owning the list property is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QQmlListReference instances even after the object is deleted.

Constructs a QQmlListReference from a QVariant variant containing a QQmlListProperty . If variant does not contain a list property, an invalid QQmlListReference is created. If the object owning the list property is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QQmlListReference instances even after the object is deleted.

Use the constructors without QQmlEngine argument instead.

Constructs a QQmlListReference from a QVariant variant containing a QQmlListProperty . If variant does not contain a list property, an invalid QQmlListReference is created. If the object owning the list property is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QQmlListReference instances even after the object is deleted.

The engine is unused.

PySide6.QtQml.QQmlListReference.append(arg__1)#
Parameters:

arg__1PySide6.QtCore.QObject

Return type:

bool

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

See also

canAppend()

PySide6.QtQml.QQmlListReference.at(arg__1)#
Parameters:

arg__1 – int

Return type:

PySide6.QtCore.QObject

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

See also

canAt()

PySide6.QtQml.QQmlListReference.canAppend()#
Return type:

bool

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

See also

append()

PySide6.QtQml.QQmlListReference.canAt()#
Return type:

bool

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

See also

at()

PySide6.QtQml.QQmlListReference.canClear()#
Return type:

bool

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

See also

clear()

PySide6.QtQml.QQmlListReference.canCount()#
Return type:

bool

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()

PySide6.QtQml.QQmlListReference.canRemoveLast()#
Return type:

bool

Returns true if the last item can be removed from the list property, otherwise false. Returns false if the reference is invalid.

See also

removeLast()

PySide6.QtQml.QQmlListReference.canReplace()#
Return type:

bool

Returns true if items in the list property can be replaced, otherwise false. Returns false if the reference is invalid.

See also

replace()

PySide6.QtQml.QQmlListReference.clear()#
Return type:

bool

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

See also

canClear()

PySide6.QtQml.QQmlListReference.count()#
Return type:

int

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

PySide6.QtQml.QQmlListReference.isManipulable()#
Return type:

bool

Return true if at() , count() , append() , and either clear() or removeLast() are implemented, so you can manipulate the list.

Mind that replace() and removeLast() can be emulated by stashing all items and rebuilding the list using clear() and append() . Therefore, they are not required for the list to be manipulable. Furthermore, clear() can be emulated using removeLast() .

PySide6.QtQml.QQmlListReference.isReadable()#
Return type:

bool

Return true if at() and count() are implemented, so you can access the elements.

PySide6.QtQml.QQmlListReference.isValid()#
Return type:

bool

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

PySide6.QtQml.QQmlListReference.listElementType()#
Return type:

PySide6.QtCore.QMetaObject

Returns the QMetaObject for the elements stored in the list property, or None 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. If you didn’t pass an engine on construction this may return nullptr.

PySide6.QtQml.QQmlListReference.object()#
Return type:

PySide6.QtCore.QObject

Returns the list property’s object. Returns None if the reference is invalid.

PySide6.QtQml.QQmlListReference.__eq__(other)#
Parameters:

otherPySide6.QtQml.QQmlListReference

Return type:

bool

Compares this QQmlListReference to other, and returns true if they are equal. The two are only considered equal if one was created from the other via copy assignment or copy construction.

Note

Independently created references to the same object are not considered to be equal.

PySide6.QtQml.QQmlListReference.removeLast()#
Return type:

bool

Removes the last item in the list. Returns true if the operation succeeded, otherwise false.

See also

canRemoveLast()

PySide6.QtQml.QQmlListReference.replace(arg__1, arg__2)#
Parameters:
Return type:

bool

Replaces the item at index in the list with object. Returns true if the operation succeeded, otherwise false.

See also

canReplace()

PySide6.QtQml.QQmlListReference.size()#
Return type:

int

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