QQmlListProperty Class
template <typename T> class QQmlListProperty
The QQmlListProperty class is a list of objects that QML documents fill. More…
| Header | #include <QQmlListProperty> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Qml) |
| Module | Nt Qml C++ Classes |
List of all members, including inherited members
Public Types
| typedef | AppendFunction |
| typedef | CountFunction |
| typedef | AtFunction |
| typedef | ClearFunction |
| typedef | ReplaceFunction |
| typedef | RemoveLastFunction |
Public Functions
| QQmlListProperty() | |
| QQmlListProperty(QObject *o, QList<T *> *list) | |
| QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ClearFunction cl) | |
| QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ClearFunction cl, ReplaceFunction r, RemoveLastFunction rl) | |
| QQmlListProperty(QObject *o, void *d, CountFunction c, AtFunction t) | |
| bool | operator==(const QQmlListProperty &o) const |
Public Variables
| QObject * | object |
| void * | data |
| AppendFunction | append |
| CountFunction | count |
| AtFunction | at |
| ClearFunction | clear |
| ReplaceFunction | replace |
| RemoveLastFunction | removeLast |
Detailed Description
A property of this type takes the objects declared in it, or assigned to it as a list. The usual way is to give it a QList that the object owns:
class Shelf : public QObject {
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> books READ books)
Q_CLASSINFO("DefaultProperty", "books")
public:
QQmlListProperty<QObject> books() { return QQmlListProperty<QObject>(this, &m_books); }
private:
QList<QObject *> m_books;
};
Functions can do the work instead of a QList, for lists that need to react to changes.
See also Using Nt QML.
Differences from Qt
Nt fills list properties of any QQmlListProperty<T> through QQmlListProperty<QObject>, so T must be a QObject subclass.
Member Type Documentation
typedef QQmlListProperty::AppendFunction
A function that appends an object to the list.
typedef QQmlListProperty::AtFunction
A function that returns the object at an index of the list.
typedef QQmlListProperty::ClearFunction
A function that empties the list.
typedef QQmlListProperty::CountFunction
A function that returns the number of objects in the list.
typedef QQmlListProperty::RemoveLastFunction
A function that removes the last object of the list.
typedef QQmlListProperty::ReplaceFunction
A function that replaces the object at an index of the list.
Member Function Documentation
QQmlListProperty::QQmlListProperty()
Constructs an invalid list property.
QQmlListProperty::QQmlListProperty(QObject *o, QList<T *> *list)
Constructs a list property of o backed by list, which o must outlive.
QQmlListProperty::QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ClearFunction cl)
Constructs a list property of o with the user data d and the functions a (append), c (count), t (at) and cl (clear).
QQmlListProperty::QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ClearFunction cl, ReplaceFunction r, RemoveLastFunction rl)
Constructs a list property of o with the user data d and the functions a (append), c (count), t (at), cl (clear), r (replace) and rl (remove last).
QQmlListProperty::QQmlListProperty(QObject *o, void *d, CountFunction c, AtFunction t)
Constructs a read-only list property of o with the user data d and the functions c (count) and t (at).
bool QQmlListProperty::operator==(const QQmlListProperty &o) const
Returns true if this list property and o have the same object, data and functions.
Member Variable Documentation
AppendFunction QQmlListProperty::append
The function that appends, or nullptr if the list is read-only.
AtFunction QQmlListProperty::at
The function that returns an object.
ClearFunction QQmlListProperty::clear
The function that empties the list, or nullptr.
CountFunction QQmlListProperty::count
The function that counts.
void * QQmlListProperty::data
The user data of the functions; the QList for the QList constructor.
QObject * QQmlListProperty::object
The object that has the list.
RemoveLastFunction QQmlListProperty::removeLast
The function that removes the last object, or nullptr.
ReplaceFunction QQmlListProperty::replace
The function that replaces an object, or nullptr.