QMetaProperty Class

The QMetaProperty class provides meta-data about a property. 更多...

頭: #include <QMetaProperty>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

公共函數

(從 6.0 起) QUntypedBindable bindable (QObject * object ) const
QMetaEnum enumerator () const
bool hasNotifySignal () const
(從 6.0 起) bool isBindable () const
bool isConstant () const
bool isDesignable () const
bool isEnumType () const
bool isFinal () const
bool isFlagType () const
bool isReadable () const
bool isRequired () const
bool isResettable () const
bool isScriptable () const
bool isStored () const
bool isUser () const
bool isValid () const
bool isWritable () const
(從 6.0 起) QMetaType metaType () const
const char * name () const
QMetaMethod notifySignal () const
int notifySignalIndex () const
int propertyIndex () const
QVariant read (const QObject * object ) const
QVariant readOnGadget (const void * gadget ) const
int relativePropertyIndex () const
bool reset (QObject * object ) const
bool resetOnGadget (void * gadget ) const
int revision () const
(從 6.0 起) int typeId () const
const char * typeName () const
int userType () const
bool write (QObject * object , const QVariant & value ) const
(從 6.6 起) bool write (QObject * object , QVariant && v ) const
bool writeOnGadget (void * gadget , const QVariant & value ) const
(從 6.6 起) bool writeOnGadget (void * gadget , QVariant && value ) const

詳細描述

Property meta-data is obtained from an object's meta-object. See QMetaObject::property () 和 QMetaObject::propertyCount () 瞭解細節。

Property Meta-Data

A property has a name () 和 metaType (), as well as various attributes that specify its behavior: isReadable (), isWritable (), isDesignable (), isScriptable (), revision (),和 isStored ().

If the property is an enumeration, isEnumType () 返迴 true ; if the property is an enumeration that is also a flag (i.e. its values can be combined using the OR operator), isEnumType () 和 isFlagType () both return true. The enumerator for these types is available from enumerator ().

The property's values are set and retrieved with read (), write (),和 reset (); they can also be changed through QObject 's set and get functions. See QObject::setProperty () 和 QObject::property () 瞭解細節。

Copying and Assignment

QMetaProperty objects can be copied by value. However, each copy will refer to the same underlying property meta-data.

另請參閱 QMetaObject , QMetaEnum , QMetaMethod ,和 Qt 的特性係統 .

成員函數文檔編製

[since 6.0] QUntypedBindable QMetaProperty:: bindable ( QObject * object ) const

Returns the bindable interface for the property on a given object .

If the property doesn't support bindings, the returned interface will be invalid.

該函數在 Qt 6.0 引入。

另請參閱 QObjectBindableProperty , QProperty ,和 isBindable ().

QMetaEnum QMetaProperty:: enumerator () const

Returns the enumerator if this property's type is an enumerator type; otherwise the returned value is undefined.

另請參閱 isEnumType () 和 isFlagType ().

bool QMetaProperty:: hasNotifySignal () const

返迴 true if this property has a corresponding change notify signal; otherwise returns false .

另請參閱 notifySignal ().

[since 6.0] bool QMetaProperty:: isBindable () const

返迴 trueQ_PROPERTY() exposes binding functionality; otherwise returns false.

This implies that you can create bindings that use this property as a dependency or install QPropertyObserver objects on this property. Unless the property is readonly, you can also set a binding on this property.

該函數在 Qt 6.0 引入。

另請參閱 QProperty , isWritable (),和 bindable ().

bool QMetaProperty:: isConstant () const

返迴 true if the property is constant; otherwise returns false .

A property is constant if the Q_PROPERTY() 's CONSTANT 屬性有設置。

bool QMetaProperty:: isDesignable () const

返迴 falseQ_PROPERTY() 's DESIGNABLE attribute is false; otherwise returns true .

另請參閱 isScriptable () 和 isStored ().

bool QMetaProperty:: isEnumType () const

返迴 true if the property's type is an enumeration value; otherwise returns false .

另請參閱 enumerator () 和 isFlagType ().

bool QMetaProperty:: isFinal () const

返迴 true if the property is final; otherwise returns false .

A property is final if the Q_PROPERTY() 's FINAL 屬性有設置。

bool QMetaProperty:: isFlagType () const

返迴 true if the property's type is an enumeration value that is used as a flag; otherwise returns false .

Flags can be combined using the OR operator. A flag type is implicitly also an enum type.

另請參閱 isEnumType (), enumerator (),和 QMetaEnum::isFlag ().

bool QMetaProperty:: isReadable () const

返迴 true if this property is readable; otherwise returns false .

另請參閱 isWritable (), read (),和 isValid ().

bool QMetaProperty:: isRequired () const

返迴 true if the property is required; otherwise returns false .

A property is final if the Q_PROPERTY() 's REQUIRED 屬性有設置。

bool QMetaProperty:: isResettable () const

返迴 true if this property can be reset to a default value; otherwise returns false .

另請參閱 reset ().

bool QMetaProperty:: isScriptable () const

返迴 falseQ_PROPERTY() 's SCRIPTABLE attribute is false; otherwise returns true.

另請參閱 isDesignable () 和 isStored ().

bool QMetaProperty:: isStored () const

返迴 true if the property is stored; otherwise returns false.

函數返迴 falseQ_PROPERTY() 's STORED attribute is false; otherwise returns true.

另請參閱 isDesignable () 和 isScriptable ().

bool QMetaProperty:: isUser () const

返迴 falseQ_PROPERTY() 's USER attribute is false. Otherwise it returns true, indicating the property is designated as the USER property, i.e., the one that the user can edit or that is significant in some other way.

另請參閱 QMetaObject::userProperty (), isDesignable (),和 isScriptable ().

bool QMetaProperty:: isValid () const

返迴 true if this property is valid (readable); otherwise returns false .

另請參閱 isReadable ().

bool QMetaProperty:: isWritable () const

返迴 true if this property is writable; otherwise returns false.

另請參閱 isReadable () 和 write ().

[since 6.0] QMetaType QMetaProperty:: metaType () const

Returns this property's QMetaType .

該函數在 Qt 6.0 引入。

另請參閱 QMetaType .

const char *QMetaProperty:: name () const

Returns this property's name.

另請參閱 type () 和 typeName ().

QMetaMethod QMetaProperty:: notifySignal () const

返迴 QMetaMethod instance of the property change notifying signal if one was specified, otherwise returns an invalid QMetaMethod .

另請參閱 hasNotifySignal ().

int QMetaProperty:: notifySignalIndex () const

Returns the index of the property change notifying signal if one was specified, otherwise returns -1.

另請參閱 hasNotifySignal ().

int QMetaProperty:: propertyIndex () const

Returns this property's index.

QVariant QMetaProperty:: read (const QObject * object ) const

Reads the property's value from the given object . Returns the value if it was able to read it; otherwise returns an invalid variant.

另請參閱 write (), reset (),和 isReadable ().

QVariant QMetaProperty:: readOnGadget (const void * gadget ) const

Reads the property's value from the given gadget . Returns the value if it was able to read it; otherwise returns an invalid variant.

This function should only be used if this is a property of a Q_GADGET

int QMetaProperty:: relativePropertyIndex () const

Returns this property's index relative within the enclosing meta object.

bool QMetaProperty:: reset ( QObject * object ) const

Resets the property for the given object with a reset method. Returns true if the reset worked; otherwise returns false .

Reset methods are optional; only a few properties support them.

另請參閱 read () 和 write ().

bool QMetaProperty:: resetOnGadget ( void * gadget ) const

Resets the property for the given gadget with a reset method. Returns true if the reset worked; otherwise returns false .

Reset methods are optional; only a few properties support them.

This function should only be used if this is a property of a Q_GADGET

int QMetaProperty:: revision () const

Returns the property revision if one was specified by Q_REVISION , otherwise returns 0. Since Qt 6.0, non-zero values are encoded and can be decoded using QTypeRevision::fromEncodedVersion ().

[since 6.0] int QMetaProperty:: typeId () const

Returns the storage type of the property. This is the same as metaType ().id().

該函數在 Qt 6.0 引入。

另請參閱 QMetaType , typeName (),和 metaType ().

const char *QMetaProperty:: typeName () const

Returns the name of this property's type.

另請參閱 type () 和 name ().

int QMetaProperty:: userType () const

Returns this property's user type. The return value is one of the values that are registered with QMetaType .

這相當於 metaType ().id()

另請參閱 type (), QMetaType , typeName (),和 metaType ().

bool QMetaProperty:: write ( QObject * object , const QVariant & value ) const

寫入 value as the property's value to the given object . Returns true if the write succeeded; otherwise returns false .

value is not of the same type as the property, a conversion is attempted. An empty QVariant() is equivalent to a call to reset () if this property is resettable, or setting a default-constructed object otherwise.

注意: This function internally makes a copy of value . Prefer to use the rvalue overload when possible.

另請參閱 read (), reset (),和 isWritable ().

[since 6.6] bool QMetaProperty:: write ( QObject * object , QVariant && v ) const

這是重載函數。

該函數在 Qt 6.6 引入。

bool QMetaProperty:: writeOnGadget ( void * gadget , const QVariant & value ) const

寫入 value as the property's value to the given gadget . Returns true if the write succeeded; otherwise returns false .

This function should only be used if this is a property of a Q_GADGET

[since 6.6] bool QMetaProperty:: writeOnGadget ( void * gadget , QVariant && value ) const

這是重載函數。

該函數在 Qt 6.6 引入。