QMetaProperty Class

The QMetaProperty class provides meta-data about a property. More...

Header: #include <QMetaProperty>

Public Functions

QMetaProperty()
QUntypedBindable bindable(QObject *object) const
const QMetaObject *enclosingMetaObject() const
QMetaEnum enumerator() const
bool hasNotifySignal() const
bool hasStdCppSet() const
bool isAlias() const
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
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
QVariant::Type type() const
int typeId() const
const char *typeName() const
int userType() const
bool write(QObject *object, const QVariant &value) const
bool write(QObject *object, QVariant &&v) const
bool writeOnGadget(void *gadget, const QVariant &value) const
bool writeOnGadget(void *gadget, QVariant &&value) const

Detailed Description

\inmoduleQtCore

\ingroupobjectmodel

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.

See also QMetaObject, QMetaEnum, QMetaMethod, and Qt's Property System.

Member Function Documentation

[constexpr] QMetaProperty::QMetaProperty()

\internal

QUntypedBindable QMetaProperty::bindable(QObject *object) const

\since6.0 Returns the bindable interface for the property on a given object.

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

See also QObjectBindableProperty, QProperty, and isBindable().

const QMetaObject *QMetaProperty::enclosingMetaObject() const

\internal

QMetaEnum QMetaProperty::enumerator() const

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

See also isEnumType() and isFlagType().

bool QMetaProperty::hasNotifySignal() const

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

See also notifySignal().

bool QMetaProperty::hasStdCppSet() const

\internal

Returns true if the property has a C++ setter function that follows Qt's standard "name" / "setName" pattern. Designer and uic query hasStdCppSet() in order to avoid expensive QObject::setProperty() calls. All properties in Qt [should] follow this pattern.

bool QMetaProperty::isAlias() const

\internal

Returns true if the property is an alias. This is for instance true for a property declared in QML as 'property alias'.

bool QMetaProperty::isBindable() const

\since6.0 Returns true if the Q_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.

See also QProperty, isWritable(), and bindable().

bool QMetaProperty::isConstant() const

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

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

bool QMetaProperty::isDesignable() const

Returns false if the Q_PROPERTY()'s DESIGNABLE attribute is false; otherwise returns true.

See also isScriptable() and isStored().

bool QMetaProperty::isEnumType() const

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

See also enumerator() and isFlagType().

bool QMetaProperty::isFinal() const

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

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

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.

See also isEnumType(), enumerator(), and QMetaEnum::isFlag().

bool QMetaProperty::isReadable() const

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

See also isWritable(), read(), and isValid().

bool QMetaProperty::isRequired() const

\since5.15 Returns true if the property is required; otherwise returns false.

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

bool QMetaProperty::isResettable() const

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

See also reset().

bool QMetaProperty::isScriptable() const

Returns false if the Q_PROPERTY()'s SCRIPTABLE attribute is false; otherwise returns true.

See also isDesignable() and isStored().

bool QMetaProperty::isStored() const

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

The function returns false if the Q_PROPERTY()'s STORED attribute is false; otherwise returns true.

See also isDesignable() and isScriptable().

bool QMetaProperty::isUser() const

Returns false if the Q_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.

See also QMetaObject::userProperty(), isDesignable(), and isScriptable().

bool QMetaProperty::isValid() const

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

See also isReadable().

bool QMetaProperty::isWritable() const

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

See also isReadable() and write().

QMetaType QMetaProperty::metaType() const

\since6.0

Returns this property's QMetaType.

See also QMetaType.

const char *QMetaProperty::name() const

Returns this property's name.

See also type() and typeName().

QMetaMethod QMetaProperty::notifySignal() const

\since4.5

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

See also hasNotifySignal().

int QMetaProperty::notifySignalIndex() const

\since4.6

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

See also hasNotifySignal().

int QMetaProperty::propertyIndex() const

\since4.6

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.

See also write(), reset(), and isReadable().

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

\since5.5

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

\since5.14

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.

See also read() and write().

bool QMetaProperty::resetOnGadget(void *gadget) const

\since5.5

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

\since5.1

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

QVariant::Type QMetaProperty::type() const

\deprecated

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

See also typeName(), name(), and metaType().

int QMetaProperty::typeId() const

\since6.0

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

See also QMetaType, typeName(), and metaType().

const char *QMetaProperty::typeName() const

Returns the name of this property's type.

See also type() and name().

int QMetaProperty::userType() const

\since4.2

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

This is equivalent to metaType().id()

See also type(), QMetaType, typeName(), and metaType().

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 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.

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

See also read(), reset(), and isWritable().

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

This is an overloaded function.

\since6.6

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

\since5.5

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

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

This is an overloaded function.

\since6.6