QMetaProperty Class
The QMetaProperty class provides meta-data about a property. More…
| Header | #include <QMetaProperty> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QMetaProperty() | |
| const char * | name() const |
| const char * | typeName() const |
| QMetaType | metaType() const |
| int | typeId() const |
| int | userType() const |
| int | propertyIndex() const |
| int | relativePropertyIndex() const |
| bool | isReadable() const |
| bool | isWritable() const |
| bool | isResettable() const |
| bool | isDesignable(const QObject *obj = nullptr) const |
| bool | isScriptable(const QObject *obj = nullptr) const |
| bool | isStored(const QObject *obj = nullptr) const |
| bool | isUser(const QObject *obj = nullptr) const |
| bool | isConstant() const |
| bool | isFinal() const |
| bool | isRequired() const |
| bool | isFlagType() const |
| bool | isEnumType() const |
| bool | isBindable() const |
| QMetaEnum | enumerator() const |
| bool | hasNotifySignal() const |
| QMetaMethod | notifySignal() const |
| int | notifySignalIndex() const |
| int | revision() const |
| const QMetaObject * | enclosingMetaObject() const |
| bool | isValid() const |
| QVariant | read(const QObject *obj) const |
| bool | write(QObject *obj, const QVariant &value) const |
| bool | reset(QObject *obj) const |
| QVariant | readOnGadget(const void *gadget) const |
| bool | writeOnGadget(void *gadget, const QVariant &value) const |
| bool | resetOnGadget(void *gadget) const |
| bool | hasStdCppSet() const |
Detailed Description
A property is declared with Q_PROPERTY(). Read and write it through a QVariant, with an object or, for a Q_GADGET, a pointer to the value:
QMetaProperty p = obj->metaObject()->property(
obj->metaObject()->indexOfProperty("interval"));
p.write(obj, 500);
int ms = p.read(obj).toInt();
Enumerations declared with Q_ENUM() can be written from their key names as well as from numbers. Writing converts the variant to the type of the property first, and fails if it cannot be converted.
See also QMetaObject::property(), QObject::property() and QMetaEnum.
Differences from Qt
Bindable properties are not supported, so isBindable() is always false and there is no bindable() or isQProperty(). The DESIGNABLE, SCRIPTABLE, STORED and USER attributes are evaluated, but EDITABLE and isEditable() are not available. Property types that are not registered with QMetaType cannot be read or written.
Member Function Documentation
QMetaProperty::QMetaProperty()
Constructs an invalid property.
See also isValid().
const QMetaObject * QMetaProperty::enclosingMetaObject() const
Returns the meta-object of the class that declares the property.
QMetaEnum QMetaProperty::enumerator() const
Returns the enumerator that describes the type of the property, or an invalid QMetaEnum if its type is not an enumeration with meta-data.
See also isEnumType().
bool QMetaProperty::hasNotifySignal() const
Returns true if the property has a NOTIFY signal.
See also notifySignal().
bool QMetaProperty::hasStdCppSet() const
Returns true if the property has a setter that follows the setName() convention. Always true for a writable property of Nt.
bool QMetaProperty::isBindable() const
Returns false: bindable properties are not supported.
bool QMetaProperty::isConstant() const
Returns true if the property is declared CONSTANT, so its value does not change for an object.
See also isFinal().
bool QMetaProperty::isDesignable(const QObject *obj = nullptr) const
Returns true if the property is designable for obj, which is the value of its DESIGNABLE attribute. The default is true. If the attribute is a function and obj is nullptr, returns true.
See also isScriptable() and isStored().
bool QMetaProperty::isEnumType() const
Returns true if the type of the property is an enumeration that has meta-data.
See also enumerator().
bool QMetaProperty::isFinal() const
Returns true if the property is declared FINAL, so no derived class overrides it.
See also isConstant().
bool QMetaProperty::isFlagType() const
Returns true if the type of the property is an enumeration declared with Q_FLAG().
See also isEnumType().
bool QMetaProperty::isReadable() const
Returns true if the property can be read.
See also read() and isWritable().
bool QMetaProperty::isRequired() const
Returns true if the property is declared REQUIRED.
See also isConstant().
bool QMetaProperty::isResettable() const
Returns true if the property has a RESET function.
See also reset().
bool QMetaProperty::isScriptable(const QObject *obj = nullptr) const
Returns true if the property is scriptable for obj, which is the value of its SCRIPTABLE attribute. The default is true.
See also isDesignable() and isStored().
bool QMetaProperty::isStored(const QObject *obj = nullptr) const
Returns true if the property is stored for obj, which is the value of its STORED attribute. The default is true.
See also isDesignable() and isUser().
bool QMetaProperty::isUser(const QObject *obj = nullptr) const
Returns true if the property is the user property of obj, which is the value of its USER attribute. The default is false.
See also QMetaObject::userProperty().
bool QMetaProperty::isValid() const
Returns true if this object describes a property; otherwise returns false.
bool QMetaProperty::isWritable() const
Returns true if the property can be written.
See also write() and isReadable().
QMetaType QMetaProperty::metaType() const
Returns the QMetaType of the property, or an invalid QMetaType if the type is not known.
See also typeId().
const char * QMetaProperty::name() const
Returns the name of the property.
See also typeName().
QMetaMethod QMetaProperty::notifySignal() const
Returns the NOTIFY signal of the property, or an invalid QMetaMethod if it has none.
See also hasNotifySignal().
int QMetaProperty::notifySignalIndex() const
Returns the index of the NOTIFY signal in its class, counting the methods of the base classes first, or -1 if the property has none.
See also notifySignal().
int QMetaProperty::propertyIndex() const
Returns the index of the property, counting the properties of the base classes first.
See also relativePropertyIndex().
QVariant QMetaProperty::read(const QObject *obj) const
Reads the property of obj and returns it as a QVariant. Returns an invalid variant if the property is not readable or its type is not registered.
See also write() and isReadable().
QVariant QMetaProperty::readOnGadget(const void *gadget) const
Reads the property of the Q_GADGET value at gadget.
See also read().
int QMetaProperty::relativePropertyIndex() const
Returns the index of the property among those of its own class.
See also propertyIndex().
bool QMetaProperty::reset(QObject *obj) const
Resets the property of obj with its RESET function and returns true, or returns false if the property cannot be reset.
See also isResettable().
bool QMetaProperty::resetOnGadget(void *gadget) const
Resets the property of the Q_GADGET value at gadget and returns true on success.
See also reset().
int QMetaProperty::revision() const
Returns the revision of the property, which is 0 unless it is declared with REVISION.
int QMetaProperty::typeId() const
Returns the QMetaType id of the property, or QMetaType::UnknownType if the type is not known.
See also metaType().
const char * QMetaProperty::typeName() const
Returns the name of the type of the property as it is declared, such as "int" or "Counter::Mode".
See also metaType().
int QMetaProperty::userType() const
Returns the QMetaType id of the property; the same as typeId().
bool QMetaProperty::write(QObject *obj, const QVariant &value) const
Writes value to the property of obj and returns true on success. value is converted to the type of the property first; for an enumeration it can also be the name of a key. Returns false if the property is not writable or the value cannot be converted. Writing an invalid variant resets a resettable property.
See also read(), reset() and isWritable().
bool QMetaProperty::writeOnGadget(void *gadget, const QVariant &value) const
Writes value to the property of the Q_GADGET value at gadget and returns true on success.
See also write().