PySide6.QtQml.QQmlListReference¶
- class QQmlListReference¶
The
QQmlListReferenceclass allows the manipulation ofQQmlListPropertyproperties.Details
QQmlListReferenceallows C++ programs to read from, and assign values to a QML list property in a simple and type-safe way. The main advantage over usingQQmlListPropertyitself is its type erasure:QQmlListReferenceis not a template, but can be used for QQmlListProperties of any type. Furthermore it watches the owner object for deletion and does not allow theQQmlListPropertyto be accessed anymore if its owner has been deleted.You can create a
QQmlListReferencefrom either an object and a property name or from a QVariant. These two are equivalent:QQmlListReference ref1(object, "children"); const QVariant var = object->property("children"); QQmlListReference ref2(var);
Not all QQmlListReferences support all operations. Methods like
canAppend(),canAt(),canClear(), andcanCount()allow programs to query whether an operation is supported on a given property. The availability of the methods depends on the methods implemented by the underlyingQQmlListProperty. When constructing aQQmlListPropertyby manually passing the accessor functions you can restrict access to the list by passing nullptr to some of them.QQmlListReferencewill recognize those and report them as unavailable.QQmlListReferences are type-safe. Only QObjects that derive of the correct base class can be added to the list. ThelistElementType()method can be used to query the QMetaObject of the QObject type that can be added. Attempting to add objects of an incorrect type to a list property will fail.Like with other 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. Use the
count()method before callingat()to this effect.Synopsis¶
Methods¶
def
__init__()def
append()def
at()def
canAppend()def
canAt()def
canClear()def
canCount()def
canRemoveLast()def
canReplace()def
clear()def
count()def
isManipulable()def
isReadable()def
isValid()def
object()def
__eq__()def
removeLast()def
replace()def
size()
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
- __init__()¶
Constructs an invalid instance.
- __init__(variant)
- Parameters:
variant –
QQmlListReference
Constructs a
QQmlListReferencefrom a QVariantvariantcontaining aQQmlListProperty. Ifvariantdoes not contain a list property, an invalidQQmlListReferenceis 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 holdQQmlListReferenceinstances even after the object is deleted.- __init__(variant)
- Parameters:
variant – object
Constructs a
QQmlListReferencefrom a QVariantvariantcontaining aQQmlListProperty. Ifvariantdoes not contain a list property, an invalidQQmlListReferenceis 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 holdQQmlListReferenceinstances even after the object is deleted.- __init__(o, property)
- Parameters:
o –
QObjectproperty – str
Constructs a
QQmlListReferenceforobject'sproperty. Ifpropertyis not a list property, an invalidQQmlListReferenceis created. Ifobjectis destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to holdQQmlListReferenceinstances even afterobjectis deleted.- __init__(variant, engine)
- Parameters:
variant – object
engine –
QQmlEngine
Note
This function is deprecated.
Use the constructors without
QQmlEngineargument instead.Constructs a
QQmlListReferencefrom a QVariantvariantcontaining aQQmlListProperty. Ifvariantdoes not contain a list property, an invalidQQmlListReferenceis 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 holdQQmlListReferenceinstances even after the object is deleted.The
engineis unused.- __init__(o, property, engine)
- Parameters:
o –
QObjectproperty – str
engine –
QQmlEngine
Note
This function is deprecated.
Use the constructors without
QQmlEngineargument instead.Constructs a
QQmlListReferenceforobject'sproperty. Ifpropertyis not a list property, an invalidQQmlListReferenceis created. Ifobjectis destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to holdQQmlListReferenceinstances even afterobjectis deleted.The
engineis unused.Appends
objectto the list. Returns true if the operation succeeded, otherwise false.See also
Returns the list element at
index, orNoneif the operation failed.See also
- 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
- 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
- canClear()¶
- Return type:
bool
Returns true if the list property can be cleared, otherwise false. Returns false if the reference is invalid.
See also
- 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
- 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
- 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
- clear()¶
- Return type:
bool
Clears the list. Returns true if the operation succeeded, otherwise false.
See also
- count()¶
- Return type:
int
Returns the number of items in the list, or 0 if the operation failed.
- isManipulable()¶
- Return type:
bool
Return true if
at(),count(),append(), and eitherclear()orremoveLast()are implemented, so you can manipulate the list.Mind that
replace()andremoveLast()can be emulated by stashing all items and rebuilding the list usingclear()andappend(). Therefore, they are not required for the list to be manipulable. Furthermore,clear()can be emulated usingremoveLast().See also
isReadable()at()count()append()clear()replace()removeLast()- isReadable()¶
- Return type:
bool
Return true if
at()andcount()are implemented, so you can access the elements.See also
- isValid()¶
- Return type:
bool
Returns true if the instance refers to a valid list property, otherwise false.
- listElementType()¶
- Return type:
Returns the QMetaObject for the elements stored in the list property, or
Noneif 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.
Returns the list property’s object. Returns
Noneif the reference is invalid.- __eq__(other)¶
- Parameters:
other –
QQmlListReference- Return type:
bool
Compares this
QQmlListReferencetoother, and returnstrueif 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.
- removeLast()¶
- Return type:
bool
Removes the last item in the list. Returns true if the operation succeeded, otherwise false.
See also
Replaces the item at
indexin the list withobject. Returns true if the operation succeeded, otherwise false.See also
- size()¶
- Return type:
int
Returns the number of items in the list, or 0 if the operation failed.