QQmlListProperty Class

The QQmlListProperty class allows applications to expose list-like properties of QObject -derived classes to QML. 更多...

頭: #include <QQmlListProperty>
qmake: QT += qml
Since: Qt 5.0

公共類型

typedef AppendFunction
typedef AtFunction
typedef ClearFunction
typedef CountFunction

公共函數

QQmlListProperty (QObject * object , QList<T *> & list )
QQmlListProperty (QObject * object , void * data , QQmlListProperty::AppendFunction append , QQmlListProperty::CountFunction count , QQmlListProperty::AtFunction at , QQmlListProperty::ClearFunction clear )
QQmlListProperty (QObject * object , void * data , QQmlListProperty::CountFunction count , QQmlListProperty::AtFunction at )
bool operator== (const QQmlListProperty<T> & other ) const

公共變量

QQmlListProperty::AppendFunction append
QQmlListProperty::AtFunction at
QQmlListProperty::ClearFunction clear
QQmlListProperty::CountFunction count
void * data
void * dummy1
void * dummy2
QObject * object

詳細描述

The QQmlListProperty class allows applications to expose list-like properties of QObject -derived classes to QML.

QML has many list properties, where more than one object value can be assigned. The use of a list property from QML looks like this:

FruitBasket {
    fruit: [
        Apple {},
        Orange{},
        Banana{}
    ]
}
					

The QQmlListProperty encapsulates a group of function pointers that represent the set of actions QML can perform on the list - adding items, retrieving items and clearing the list. In the future, additional operations may be supported. All list properties must implement the append operation, but the rest are optional.

To provide a list property, a C++ class must implement the operation callbacks, and then return an appropriate QQmlListProperty value from the property getter. List properties should have no setter. In the example above, the Q_PROPERTY () declarative will look like this:

Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
					

QML list properties are type-safe - in this case Fruit QObject type that Apple , Orange and Banana all derive from.

另請參閱 擴展 QML - 對象和列錶特性類型範例 .

成員類型文檔編製

typedef QQmlListProperty:: AppendFunction

同義詞 void (*)(QQmlListProperty<T> *property, T *value) .

Append the value to the list property .

typedef QQmlListProperty:: AtFunction

同義詞 T *(*)(QQmlListProperty<T> *property, int index) .

Return the element at position index in the list property .

typedef QQmlListProperty:: ClearFunction

同義詞 void (*)(QQmlListProperty<T> *property) .

Clear the list property .

typedef QQmlListProperty:: CountFunction

同義詞 int (*)(QQmlListProperty<T> *property) .

Return the number of elements in the list property .

成員函數文檔編製

QQmlListProperty:: QQmlListProperty ( QObject * object , QList < T *> & list )

Convenience constructor for making a QQmlListProperty value from an existing QList list list reference must remain valid for as long as object exists. object must be provided.

Generally this constructor should not be used in production code, as a writable QList violates QML's memory management rules. However, this constructor can be very useful while prototyping.

QQmlListProperty:: QQmlListProperty ( QObject * object , void * data , QQmlListProperty::AppendFunction append , QQmlListProperty::CountFunction count , QQmlListProperty::AtFunction at , QQmlListProperty::ClearFunction clear )

構造 QQmlListProperty from a set of operation functions append , count , at ,和 clear . An opaque data handle may be passed which can be accessed from within the operation functions. The list property remains valid while object exists.

Null pointers can be passed for any function. If any null pointers are passed in, the list will be neither designable nor alterable by the debugger. It is recommended to provide valid pointers for all functions.

QQmlListProperty:: QQmlListProperty ( QObject * object , void * data , QQmlListProperty::CountFunction count , QQmlListProperty::AtFunction at )

Construct a readonly QQmlListProperty from a set of operation functions count and at . An opaque data handle may be passed which can be accessed from within the operation functions. The list property remains valid while object exists.

bool QQmlListProperty:: operator== (const QQmlListProperty < T > & other ) const

返迴 true,若此 QQmlListProperty 等於 other ,否則 false。