Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQmlListReference Class Reference

The QQmlListReference class allows the manipulation of QQmlListProperty properties. More...

#include <qqmllist.h>

+ Collaboration diagram for QQmlListReference:

Public Member Functions

 QQmlListReference ()
 Constructs an invalid instance.
 
 QQmlListReference (const QVariant &variant)
 
 QQmlListReference (QObject *o, const char *property)
 Constructs a QQmlListReference for object's property.
 
 QQmlListReference (const QQmlListReference &)
 
QQmlListReferenceoperator= (const QQmlListReference &)
 
 ~QQmlListReference ()
 
bool isValid () const
 Returns true if the instance refers to a valid list property, otherwise false.
 
QObjectobject () const
 Returns the list property's object.
 
const QMetaObjectlistElementType () const
 Returns the QMetaObject for the elements stored in the list property, or \nullptr if the reference is invalid.
 
bool canAppend () const
 Returns true if the list property can be appended to, otherwise false.
 
bool canAt () const
 Returns true if the list property can queried by index, otherwise false.
 
bool canClear () const
 Returns true if the list property can be cleared, otherwise false.
 
bool canCount () const
 Returns true if the list property can be queried for its element count, otherwise false.
 
bool canReplace () const
 Returns true if items in the list property can be replaced, otherwise false.
 
bool canRemoveLast () const
 Returns true if the last item can be removed from the list property, otherwise false.
 
bool isManipulable () const
 
bool isReadable () const
 
bool append (QObject *) const
 Appends object to the list.
 
QObjectat (qsizetype) const
 Returns the list element at index, or 0 if the operation failed.
 
bool clear () const
 Clears the list.
 
qsizetype count () const
 Returns the number of objects in the list, or 0 if the operation failed.
 
qsizetype size () const
 
bool replace (qsizetype, QObject *) const
 Replaces the item at index in the list with object.
 
bool removeLast () const
 Removes the last item in the list.
 
bool operator== (const QQmlListReference &other) const
 Compares this QQmlListReference to other, and returns true if they are equal.
 

Friends

class QQmlListReferencePrivate
 

Detailed Description

The QQmlListReference class allows the manipulation of QQmlListProperty properties.

Since
5.0 \inmodule QtQml

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());
The QQmlListReference class allows the manipulation of QQmlListProperty properties.
Definition qqmllist.h:183
The QQmlProperty class abstracts accessing properties on objects created from QML.

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

Definition at line 182 of file qqmllist.h.

Constructor & Destructor Documentation

◆ QQmlListReference() [1/4]

QQmlListReference::QQmlListReference ( )

Constructs an invalid instance.

Definition at line 85 of file qqmllist.cpp.

◆ QQmlListReference() [2/4]

QQmlListReference::QQmlListReference ( const QVariant & variant)
explicit
Since
6.1

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.

Definition at line 132 of file qqmllist.cpp.

References QVariant::constData(), QMetaType::IsQmlList, QVariant::metaType(), QQmlListProperty< T >::object, QQmlListReferencePrivate::object, QQmlListReferencePrivate::property, QQmlListReferencePrivate::propertyType, QQmlListReferencePrivate, and variant.

+ Here is the call graph for this function:

◆ QQmlListReference() [3/4]

QQmlListReference::QQmlListReference ( QObject * object,
const char * property )

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.

Definition at line 154 of file qqmllist.cpp.

References args, QMetaObject::metacall(), object(), QQmlListReferencePrivate::object, QQmlListReferencePrivate::property, QQmlPropertyCache::property(), property, QQmlListReferencePrivate::propertyType, QQmlListReferencePrivate, and QMetaObject::ReadProperty.

+ Here is the call graph for this function:

◆ QQmlListReference() [4/4]

QQmlListReference::QQmlListReference ( const QQmlListReference & o)

Definition at line 174 of file qqmllist.cpp.

References QQmlListReferencePrivate::addref().

+ Here is the call graph for this function:

◆ ~QQmlListReference()

QQmlListReference::~QQmlListReference ( )

Definition at line 190 of file qqmllist.cpp.

References QQmlListReferencePrivate::release().

+ Here is the call graph for this function:

Member Function Documentation

◆ append()

bool QQmlListReference::append ( QObject * object) const

Appends object to the list.

Returns true if the operation succeeded, otherwise false.

See also
canAppend()

Definition at line 326 of file qqmllist.cpp.

References QQmlListProperty< T >::append, canAppend(), isObjectCompatible(), and QQmlListReferencePrivate::property.

+ Here is the call graph for this function:

◆ at()

QObject * QQmlListReference::at ( qsizetype index) const

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

See also
canAt()

Definition at line 343 of file qqmllist.cpp.

References QQmlListProperty< T >::at, canAt(), and QQmlListReferencePrivate::property.

Referenced by QQmlListAccessor::at().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canAppend()

bool QQmlListReference::canAppend ( ) const

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

Returns false if the reference is invalid.

See also
append()

Definition at line 230 of file qqmllist.cpp.

References QQmlListProperty< T >::append, isValid(), and QQmlListReferencePrivate::property.

Referenced by append().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canAt()

bool QQmlListReference::canAt ( ) const

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

Returns false if the reference is invalid.

See also
at()

Definition at line 241 of file qqmllist.cpp.

References QQmlListProperty< T >::at, isValid(), and QQmlListReferencePrivate::property.

Referenced by at().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canClear()

bool QQmlListReference::canClear ( ) const

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

Returns false if the reference is invalid.

See also
clear()

Definition at line 252 of file qqmllist.cpp.

References QQmlListProperty< T >::clear, isValid(), and QQmlListReferencePrivate::property.

Referenced by clear().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canCount()

bool QQmlListReference::canCount ( ) const

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

Definition at line 263 of file qqmllist.cpp.

References QQmlListProperty< T >::count, isValid(), and QQmlListReferencePrivate::property.

Referenced by count().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canRemoveLast()

bool QQmlListReference::canRemoveLast ( ) const

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

Definition at line 285 of file qqmllist.cpp.

References isValid(), QQmlListReferencePrivate::property, and QQmlListProperty< T >::removeLast.

Referenced by removeLast().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canReplace()

bool QQmlListReference::canReplace ( ) const

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

Returns false if the reference is invalid.

See also
replace()

Definition at line 274 of file qqmllist.cpp.

References isValid(), QQmlListReferencePrivate::property, and QQmlListProperty< T >::replace.

Referenced by replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

bool QQmlListReference::clear ( ) const

Clears the list.

Returns true if the operation succeeded, otherwise false.

See also
canClear()

Definition at line 355 of file qqmllist.cpp.

References canClear(), QQmlListProperty< T >::clear, and QQmlListReferencePrivate::property.

+ Here is the call graph for this function:

◆ count()

qsizetype QQmlListReference::count ( ) const

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

Definition at line 367 of file qqmllist.cpp.

References canCount(), QQmlListProperty< T >::count, and QQmlListReferencePrivate::property.

+ Here is the call graph for this function:

◆ isManipulable()

bool QQmlListReference::isManipulable ( ) const
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().
See also
isReadable(), at(), count(), append(), clear(), replace(), removeLast()

Definition at line 301 of file qqmllist.cpp.

References QQmlListProperty< T >::append, QQmlListProperty< T >::at, QQmlListProperty< T >::clear, QQmlListProperty< T >::count, isValid(), and QQmlListReferencePrivate::property.

+ Here is the call graph for this function:

◆ isReadable()

bool QQmlListReference::isReadable ( ) const
Return true if at() and count() are implemented, so you can access the elements.
See also
isManipulable(), at(), count()

Definition at line 316 of file qqmllist.cpp.

References QQmlListProperty< T >::at, QQmlListProperty< T >::count, isValid(), and QQmlListReferencePrivate::property.

+ Here is the call graph for this function:

◆ isValid()

bool QQmlListReference::isValid ( ) const

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

Definition at line 198 of file qqmllist.cpp.

References QQmlListReferencePrivate::object.

Referenced by canAppend(), canAt(), canClear(), canCount(), canRemoveLast(), canReplace(), isManipulable(), isReadable(), listElementType(), and object().

+ Here is the caller graph for this function:

◆ listElementType()

const QMetaObject * QQmlListReference::listElementType ( ) const

Returns the QMetaObject for the elements stored in the list property, or \nullptr 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.

Definition at line 219 of file qqmllist.cpp.

References QQmlListReferencePrivate::elementType(), and isValid().

+ Here is the call graph for this function:

◆ object()

QObject * QQmlListReference::object ( ) const

Returns the list property's object.

Returns \nullptr if the reference is invalid.

Definition at line 206 of file qqmllist.cpp.

References isValid(), and QQmlListReferencePrivate::object.

Referenced by QQmlListReference().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

QQmlListReference & QQmlListReference::operator= ( const QQmlListReference & o)

Definition at line 181 of file qqmllist.cpp.

References o, and QQmlListReferencePrivate::release().

+ Here is the call graph for this function:

◆ operator==()

bool QQmlListReference::operator== ( const QQmlListReference & other) const
inline

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.

Definition at line 223 of file qqmllist.h.

References d, and other().

+ Here is the call graph for this function:

◆ removeLast()

bool QQmlListReference::removeLast ( ) const

Removes the last item in the list.

Returns true if the operation succeeded, otherwise false.

See also
canRemoveLast()

Definition at line 404 of file qqmllist.cpp.

References canRemoveLast(), QQmlListReferencePrivate::property, and QQmlListProperty< T >::removeLast.

+ Here is the call graph for this function:

◆ replace()

bool QQmlListReference::replace ( qsizetype index,
QObject * object ) const

Replaces the item at index in the list with object.

Returns true if the operation succeeded, otherwise false.

See also
canReplace()

Definition at line 386 of file qqmllist.cpp.

References canReplace(), isObjectCompatible(), QQmlListReferencePrivate::property, and QQmlListProperty< T >::replace.

+ Here is the call graph for this function:

◆ size()

qsizetype QQmlListReference::size ( ) const
inline
Since
6.2 Returns the number of objects in the list, or 0 if the operation failed.

Definition at line 220 of file qqmllist.h.

Friends And Related Symbol Documentation

◆ QQmlListReferencePrivate

friend class QQmlListReferencePrivate
friend

Definition at line 226 of file qqmllist.h.

Referenced by QQmlListReference(), and QQmlListReference().


The documentation for this class was generated from the following files: