QMetaProperty Class

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

头文件: #include <QMetaProperty>
qmake: QT += core

公有函数

QMetaEnum enumerator() const
bool hasNotifySignal() const
bool isConstant() const
bool isDesignable(const QObject *object = Q_NULLPTR) const
bool isEnumType() const
bool isFinal() const
bool isFlagType() const
bool isReadable() const
bool isResettable() const
bool isScriptable(const QObject *object = Q_NULLPTR) const
bool isStored(const QObject *object = Q_NULLPTR) const
bool isUser(const QObject *object = Q_NULLPTR) const
bool isValid() const
bool isWritable() 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
bool reset(QObject *object) const
bool resetOnGadget(void *gadget) const
int revision() const
QVariant::Type type() const
const char *typeName() const
int userType() const
bool write(QObject *object, const QVariant &value) const
bool writeOnGadget(void *gadget, const QVariant &value) const

详细描述

The QMetaProperty class provides meta-data about a property.

Property meta-data is obtained from an object's meta-object. See QMetaObject::property() and QMetaObject::propertyCount() for details.

Property Meta-Data

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

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

The property's values are set and retrieved with read(), write(), and reset(); they can also be changed through QObject's set and get functions. See QObject::setProperty() and QObject::property() for details.

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, and Qt's Property System.

成员函数

QMetaEnum QMetaProperty::enumerator() const

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

参见 isEnumType() and isFlagType().

bool QMetaProperty::hasNotifySignal() const

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

参见 notifySignal().

bool QMetaProperty::isConstant() const

Returns true if the property is constant; otherwise returns false.

A property is constant if the Q_PROPERTY()'s CONSTANT attribute is set.

This function was introduced in Qt 4.6.

bool QMetaProperty::isDesignable(const QObject *object = Q_NULLPTR) const

Returns true if this property is designable for the given object; otherwise returns false.

If no object is given, the function returns false if the Q_PROPERTY()'s DESIGNABLE attribute is false; otherwise returns true (if the attribute is true or is a function or expression).

参见 isScriptable() and isStored().

bool QMetaProperty::isEnumType() const

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

参见 enumerator() and isFlagType().

bool QMetaProperty::isFinal() const

Returns true if the property is final; otherwise returns false.

A property is final if the Q_PROPERTY()'s FINAL attribute is set.

This function was introduced in Qt 4.6.

bool QMetaProperty::isFlagType() const

Returns 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(), and QMetaEnum::isFlag().

bool QMetaProperty::isReadable() const

Returns true if this property is readable; otherwise returns false.

参见 isWritable(), read(), and isValid().

bool QMetaProperty::isResettable() const

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

参见 reset().

bool QMetaProperty::isScriptable(const QObject *object = Q_NULLPTR) const

Returns true if the property is scriptable for the given object; otherwise returns false.

If no object is given, the function returns false if the Q_PROPERTY()'s SCRIPTABLE attribute is false; otherwise returns true (if the attribute is true or is a function or expression).

参见 isDesignable() and isStored().

bool QMetaProperty::isStored(const QObject *object = Q_NULLPTR) const

Returns true if the property is stored for object; otherwise returns false.

If no object is given, the function returns false if the Q_PROPERTY()'s STORED attribute is false; otherwise returns true (if the attribute is true or is a function or expression).

参见 isDesignable() and isScriptable().

bool QMetaProperty::isUser(const QObject *object = Q_NULLPTR) const

Returns true if this property is designated as the USER property, i.e., the one that the user can edit for object or that is significant in some other way. Otherwise it returns false. e.g., the text property is the USER editable property of a QLineEdit.

If object is null, the function returns false if the Q_PROPERTY()'s USER attribute is false. Otherwise it returns true.

参见 QMetaObject::userProperty(), isDesignable(), and isScriptable().

bool QMetaProperty::isValid() const

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

参见 isReadable().

bool QMetaProperty::isWritable() const

Returns true if this property is writable; otherwise returns false.

参见 isReadable() and write().

const char *QMetaProperty::name() const

Returns this property's name.

参见 type() and typeName().

QMetaMethod QMetaProperty::notifySignal() const

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

This function was introduced in Qt 4.5.

参见 hasNotifySignal().

int QMetaProperty::notifySignalIndex() const

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

This function was introduced in Qt 4.6.

参见 hasNotifySignal().

int QMetaProperty::propertyIndex() const

Returns this property's index.

This function was introduced in Qt 4.6.

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

This function was introduced in Qt 5.5.

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

This function was introduced in Qt 5.5.

int QMetaProperty::revision() const

Returns the property revision if one was specified by REVISION, otherwise returns 0.

This function was introduced in Qt 5.1.

QVariant::Type QMetaProperty::type() const

Returns this property's type. The return value is one of the values of the QVariant::Type enumeration.

参见 userType(), typeName(), and name().

const char *QMetaProperty::typeName() const

Returns the name of this property's type.

参见 type() and name().

int QMetaProperty::userType() const

Returns this property's user type. The return value is one of the values that are registered with QMetaType, or QMetaType::UnknownType if the type is not registered.

This function was introduced in Qt 4.2.

参见 type(), QMetaType, and typeName().

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

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

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

参见 read(), reset(), and isWritable().

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

Writes 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

This function was introduced in Qt 5.5.