The QQmlListReference class allows the manipulation of QQmlListProperty 特性。 更多...
头: | #include <QQmlListReference> |
qmake: | QT += qml |
Since: | Qt 5.0 |
QQmlListReference () | |
QQmlListReference (QObject * object , const char * property , QQmlEngine * engine = nullptr) | |
bool | append (QObject * object ) const |
QObject * | at (int index ) const |
bool | canAppend () const |
bool | canAt () const |
bool | canClear () const |
bool | canCount () const |
bool | clear () const |
int | count () const |
bool | isManipulable () const |
bool | isReadable () const |
bool | isValid () const |
const QMetaObject * | listElementType () const |
QObject * | 对象 () const |
The QQmlListReference class allows the manipulation of QQmlListProperty 特性。
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 () 和 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 的 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 ().
Constructs an invalid instance.
构造 QQmlListReference for object 's property 。若 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 被删除。
传递 engine is required to access some QML created list properties. If in doubt, and an engine is available, pass it.
追加 object to the list. Returns true if the operation succeeded, otherwise false.
另请参阅 canAppend ().
Returns the list element at index , or 0 if the operation failed.
另请参阅 canAt ().
Returns true if the list property can be appended to, otherwise false. Returns false if the reference is invalid.
另请参阅 append ().
Returns true if the list property can queried by index, otherwise false. Returns false if the reference is invalid.
另请参阅 at ().
Returns true if the list property can be cleared, otherwise false. Returns false if the reference is invalid.
另请参阅 clear ().
Returns true if the list property can be queried for its element count, otherwise false. Returns false if the reference is invalid.
另请参阅 count ().
Clears the list. Returns true if the operation succeeded, otherwise false.
另请参阅 canClear ().
Returns the number of objects in the list, or 0 if the operation failed.
返回 True 若 at (), count (), append () 和 clear () are implemented, so you can manipulate the list.
另请参阅 isReadable (), at (), count (), append (),和 clear ().
返回 True 若 at () 和 count () are implemented, so you can access the elements.
另请参阅 isManipulable (), at (),和 count ().
Returns true if the instance refers to a valid list property, otherwise false.
返回
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.
Returns the list property's object. Returns
nullptr
if the reference is invalid.