Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QMetaProperty Class Reference

\inmodule QtCore More...

#include <qmetaobject.h>

+ Collaboration diagram for QMetaProperty:

Public Member Functions

constexpr QMetaProperty ()
 
const char * name () const
 Returns this property's name.
 
const char * typeName () const
 Returns the name of this property's type.
 
int userType () const
 
int typeId () const
 
QMetaType metaType () const
 
int propertyIndex () const
 
int relativePropertyIndex () const
 
bool isReadable () const
 Returns true if this property is readable; otherwise returns false.
 
bool isWritable () const
 Returns true if this property is writable; otherwise returns false.
 
bool isResettable () const
 Returns true if this property can be reset to a default value; otherwise returns false.
 
bool isDesignable () const
 Returns false if the {Q_PROPERTY()}'s DESIGNABLE attribute is false; otherwise returns true.
 
bool isScriptable () const
 Returns false if the {Q_PROPERTY()}'s SCRIPTABLE attribute is false; otherwise returns true.
 
bool isStored () const
 Returns true if the property is stored; otherwise returns false.
 
bool isUser () const
 Returns false if the {Q_PROPERTY()}'s USER attribute is false.
 
bool isConstant () const
 
bool isFinal () const
 
bool isRequired () const
 
bool isBindable () const
 
bool isFlagType () const
 Returns true if the property's type is an enumeration value that is used as a flag; otherwise returns false.
 
bool isEnumType () const
 Returns true if the property's type is an enumeration value; otherwise returns false.
 
QMetaEnum enumerator () const
 Returns the enumerator if this property's type is an enumerator type; otherwise the returned value is undefined.
 
bool hasNotifySignal () const
 Returns true if this property has a corresponding change notify signal; otherwise returns false.
 
QMetaMethod notifySignal () const
 
int notifySignalIndex () const
 
int revision () const
 
QVariant read (const QObject *obj) const
 Reads the property's value from the given object.
 
bool write (QObject *obj, const QVariant &value) const
 Writes value as the property's value to the given object.
 
bool write (QObject *obj, QVariant &&value) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool reset (QObject *obj) const
 Resets the property for the given object with a reset method.
 
QUntypedBindable bindable (QObject *object) const
 
QVariant readOnGadget (const void *gadget) const
 
bool writeOnGadget (void *gadget, const QVariant &value) const
 
bool writeOnGadget (void *gadget, QVariant &&value) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool resetOnGadget (void *gadget) const
 
bool hasStdCppSet () const
 
bool isAlias () const
 
bool isValid () const
 Returns true if this property is valid (readable); otherwise returns false.
 
const QMetaObjectenclosingMetaObject () const
 

Friends

struct QMetaObject
 
struct QMetaObjectPrivate
 

Detailed Description

\inmodule QtCore

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.

Definition at line 321 of file qmetaobject.h.

Constructor & Destructor Documentation

◆ QMetaProperty()

QMetaProperty::QMetaProperty ( )
inlineconstexpr

Definition at line 324 of file qmetaobject.h.

Member Function Documentation

◆ bindable()

QUntypedBindable QMetaProperty::bindable ( QObject object) const
Since
6.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, isBindable()

Definition at line 3758 of file qmetaobject.cpp.

References bindable(), QMetaObject::BindableProperty, QMetaObject::metacall(), and QMetaObject::propertyOffset().

Referenced by QUntypedBindable::QUntypedBindable(), bindable(), QQmlAnyBinding::ofProperty(), QQmlAnyBinding::removeBindingFrom(), and QQmlAnyBinding::takeFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enclosingMetaObject()

const QMetaObject * QMetaProperty::enclosingMetaObject ( ) const
inline

Definition at line 379 of file qmetaobject.h.

◆ enumerator()

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

Definition at line 3613 of file qmetaobject.cpp.

Referenced by QQmlPropertyPrivate::writeEnumProperty().

+ Here is the caller graph for this function:

◆ hasNotifySignal()

bool QMetaProperty::hasNotifySignal ( ) const

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

See also
notifySignal()

Definition at line 3850 of file qmetaobject.cpp.

Referenced by QQmlWatchProxy::QQmlWatchProxy(), QUntypedBindable::QUntypedBindable(), QMetaObjectBuilder::addProperty(), QQmlProperty::connectNotifySignal(), QQmlProperty::connectNotifySignal(), QQmlPropertyPrivate::findSignalByName(), QQmlDesignerMetaObject::metaCall(), and QQmlBindEntry::setTarget().

+ Here is the caller graph for this function:

◆ hasStdCppSet()

bool QMetaProperty::hasStdCppSet ( ) const

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.

Definition at line 3523 of file qmetaobject.cpp.

References StdCppSet.

Referenced by QMetaObjectBuilder::addProperty().

+ Here is the caller graph for this function:

◆ isAlias()

bool QMetaProperty::isAlias ( ) const

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

Definition at line 3537 of file qmetaobject.cpp.

References Alias.

◆ isBindable()

bool QMetaProperty::isBindable ( ) const
Since
6.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(), bindable()

Definition at line 4039 of file qmetaobject.cpp.

References Bindable.

Referenced by QUntypedBindable::QUntypedBindable(), and removePendingQPropertyBinding().

+ Here is the caller graph for this function:

◆ isConstant()

bool QMetaProperty::isConstant ( ) const
Since
4.6 Returns true if the property is constant; otherwise returns false.

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

Definition at line 3995 of file qmetaobject.cpp.

References Constant.

Referenced by QMetaObjectBuilder::addProperty(), and QQmlProperty::needsNotifySignal().

+ Here is the caller graph for this function:

◆ isDesignable()

bool QMetaProperty::isDesignable ( ) const

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

See also
isScriptable(), isStored()

Definition at line 3936 of file qmetaobject.cpp.

References Designable.

Referenced by QMetaObjectBuilder::addProperty().

+ Here is the caller graph for this function:

◆ isEnumType()

bool QMetaProperty::isEnumType ( ) const

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

See also
enumerator(), isFlagType()

Definition at line 3507 of file qmetaobject.cpp.

References EnumOrFlag, and QMetaEnum::name().

Referenced by QMetaObjectBuilder::addProperty(), isFlagType(), write(), and QQmlPropertyPrivate::writeEnumProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFinal()

bool QMetaProperty::isFinal ( ) const
Since
4.6 Returns true if the property is final; otherwise returns false.

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

Definition at line 4009 of file qmetaobject.cpp.

References Final.

Referenced by QMetaObjectBuilder::addProperty().

+ Here is the caller graph for this function:

◆ isFlagType()

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

Definition at line 3496 of file qmetaobject.cpp.

References isEnumType(), and QMetaEnum::isFlag().

Referenced by write(), and QQmlPropertyPrivate::writeEnumProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isReadable()

bool QMetaProperty::isReadable ( ) const

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

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

Definition at line 3837 of file qmetaobject.cpp.

References Readable.

Referenced by QMetaObjectBuilder::addProperty(), allSubObjects(), generateInterfaceXml(), propertyNameListForWritableProperties(), and readAllProperties().

+ Here is the caller graph for this function:

◆ isRequired()

bool QMetaProperty::isRequired ( ) const
Since
5.15 Returns true if the property is required; otherwise returns false.

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

Definition at line 4023 of file qmetaobject.cpp.

References Required.

◆ isResettable()

bool QMetaProperty::isResettable ( ) const

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

See also
reset()

Definition at line 3825 of file qmetaobject.cpp.

References Resettable.

Referenced by QMetaObjectBuilder::addProperty(), reset(), and write().

+ Here is the caller graph for this function:

◆ isScriptable()

bool QMetaProperty::isScriptable ( ) const

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

See also
isDesignable(), isStored()

Definition at line 3949 of file qmetaobject.cpp.

References Scriptable.

Referenced by QMetaObjectBuilder::addProperty(), generateInterfaceXml(), qDBusPropertyGet(), readAllProperties(), and writeProperty().

+ Here is the caller graph for this function:

◆ 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(), isScriptable()

Definition at line 3966 of file qmetaobject.cpp.

References Stored.

Referenced by QMetaObjectBuilder::addProperty().

+ Here is the caller graph for this function:

◆ isUser()

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

Definition at line 3981 of file qmetaobject.cpp.

References User.

Referenced by QMetaObjectBuilder::addProperty(), and QMetaObject::userProperty().

+ Here is the caller graph for this function:

◆ isValid()

bool QMetaProperty::isValid ( ) const
inline

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

See also
isReadable()

Definition at line 378 of file qmetaobject.h.

Referenced by QUntypedBindable::QUntypedBindable(), QQmlBinding::dependencies(), QQmlPropertyPrivate::initProperty(), QQuickMultiPointHandlerPrivate::xMetaProperty(), and QQuickMultiPointHandlerPrivate::yMetaProperty().

+ Here is the caller graph for this function:

◆ isWritable()

bool QMetaProperty::isWritable ( ) const

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

See also
isReadable(), write()

Definition at line 3923 of file qmetaobject.cpp.

References Writable.

Referenced by QMetaObjectBuilder::addProperty(), allSubObjects(), generateInterfaceXml(), propertyNameListForWritableProperties(), write(), write(), QQmlPropertyPrivate::writeEnumProperty(), and writeProperty().

+ Here is the caller graph for this function:

◆ metaType()

◆ name()

const char * QMetaProperty::name ( ) const

Returns this property's name.

See also
type(), typeName()

Definition at line 3392 of file qmetaobject.cpp.

References rawStringData().

Referenced by QUntypedBindable::QUntypedBindable(), QMetaObjectBuilder::addProperty(), QQuickDesignerSupportProperties::allPropertyNames(), allSubObjects(), QQmlBinding::dependencies(), doWriteProperties(), doWriteProperties(), doWriteProperties(), QQmlContextData::findObjectId(), for(), generateInterfaceXml(), QQmlProperty::name(), QQmlDesignerMetaObject::notifyPropertyChange(), notifySignalIndex(), QDBusAbstractInterfacePrivate::property(), propertyNameListForWritableProperties(), and readAllProperties().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ notifySignal()

QMetaMethod QMetaProperty::notifySignal ( ) const
Since
4.5

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

See also
hasNotifySignal()

Definition at line 3865 of file qmetaobject.cpp.

References QMetaObject::method(), and notifySignalIndex().

Referenced by QMetaObjectBuilder::addProperty(), QQmlProperty::connectNotifySignal(), QQmlPropertyPrivate::findSignalByName(), and QQmlBindEntry::setTarget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ notifySignalIndex()

int QMetaProperty::notifySignalIndex ( ) const
Since
4.6

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

See also
hasNotifySignal()

Definition at line 3882 of file qmetaobject.cpp.

References QByteArray::constData(), IsUnresolvedSignal, QMetaObject::methodOffset(), name(), objectClassName(), qWarning, and stringData().

Referenced by QQmlWatchProxy::QQmlWatchProxy(), QUntypedBindable::QUntypedBindable(), QQmlProperty::connectNotifySignal(), and notifySignal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propertyIndex()

int QMetaProperty::propertyIndex ( ) const
Since
4.6

Returns this property's index.

Definition at line 3467 of file qmetaobject.cpp.

References QMetaObject::propertyOffset().

Referenced by QUntypedBindable::QUntypedBindable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

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

Definition at line 3624 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, QMetaObject::metacall(), QMetaObject::Data::metaTypes, priv(), PropertyAccessInStaticMetaCall, QMetaObject::propertyOffset(), QMetaObject::ReadProperty, and QMetaObject::Data::static_metacall.

Referenced by QQuickPropertyChanges::actions(), QQuickDesignerSupportProperties::allPropertyNames(), allSubObjects(), QQmlContextData::findObjectId(), getValueFromProperty(), QQmlDesignerMetaObject::metaCall(), QQmlWatchProxy::notifyValueChanged(), propertyNameListForWritableProperties(), qDBusPropertyGet(), readAllProperties(), readOnGadget(), and QQuickDesignerSupportProperties::readQObjectProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readOnGadget()

QVariant QMetaProperty::readOnGadget ( const void gadget) const
Since
5.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

Definition at line 3773 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, priv(), PropertyAccessInStaticMetaCall, Q_ASSERT, read(), and QMetaObject::Data::static_metacall.

Referenced by VDMListDelegateDataType::value().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ relativePropertyIndex()

int QMetaProperty::relativePropertyIndex ( ) const
Since
5.14

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

Definition at line 3479 of file qmetaobject.cpp.

◆ reset()

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

Definition at line 3737 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, isResettable(), QMetaObject::metacall(), priv(), PropertyAccessInStaticMetaCall, QMetaObject::propertyOffset(), QMetaObject::ResetProperty, and QMetaObject::Data::static_metacall.

+ Here is the call graph for this function:

◆ resetOnGadget()

bool QMetaProperty::resetOnGadget ( void gadget) const
Since
5.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

Definition at line 3813 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, priv(), PropertyAccessInStaticMetaCall, Q_ASSERT, and QMetaObject::Data::static_metacall.

+ Here is the call graph for this function:

◆ revision()

int QMetaProperty::revision ( ) const
Since
5.1

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

Definition at line 3910 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addProperty(), and main().

+ Here is the caller graph for this function:

◆ typeId()

int QMetaProperty::typeId ( ) const
inline
Since
6.0

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

See also
QMetaType, typeName(), metaType()

Definition at line 337 of file qmetaobject.h.

◆ typeName()

const char * QMetaProperty::typeName ( ) const

Returns the name of this property's type.

See also
type(), name()

Definition at line 3404 of file qmetaobject.cpp.

References QMetaType::isValid(), metaType(), and rawTypeNameFromTypeInfo().

Referenced by QQmlVMEResolvedList::QQmlVMEResolvedList(), QMetaObjectBuilder::addProperty(), QDBusAbstractInterfacePrivate::property(), QQmlProperty::propertyTypeName(), and writeProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ userType()

int QMetaProperty::userType ( ) const
inline
Since
4.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(), metaType()

Definition at line 336 of file qmetaobject.h.

Referenced by QQmlDesignerMetaObject::metaCall().

+ Here is the caller graph for this function:

◆ write() [1/2]

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

Definition at line 3673 of file qmetaobject.cpp.

References isWritable(), and write().

Referenced by QtPrivate::PropertyAdaptorSlotObjectHelpers::bindingWrapper(), write(), writeOnGadget(), writeOnGadget(), and writeProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.6

Definition at line 3684 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, isEnumType(), isFlagType(), isResettable(), isWritable(), QMetaEnum::keysToValue(), QMetaEnum::keyToValue(), QMetaObject::metacall(), QMetaObject::Data::metaTypes, ok, priv(), PropertyAccessInStaticMetaCall, QMetaObject::propertyOffset(), QMetaObject::Data::static_metacall, and QMetaObject::WriteProperty.

+ Here is the call graph for this function:

◆ writeOnGadget() [1/2]

bool QMetaProperty::writeOnGadget ( void gadget,
const QVariant value 
) const
Since
5.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

Definition at line 3787 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, priv(), PropertyAccessInStaticMetaCall, Q_ASSERT, QMetaObject::Data::static_metacall, and write().

Referenced by doWriteProperties(), doWriteProperties(), doWriteProperties(), doWriteProperty(), and VDMListDelegateDataType::setValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeOnGadget() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.6

Definition at line 3797 of file qmetaobject.cpp.

References QMetaObject::d, QMetaObject::Data::data, QMetaObjectPrivate::flags, priv(), PropertyAccessInStaticMetaCall, Q_ASSERT, QMetaObject::Data::static_metacall, and write().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 407 of file qmetaobject.h.

◆ QMetaObjectPrivate

friend struct QMetaObjectPrivate
friend

Definition at line 408 of file qmetaobject.h.


The documentation for this class was generated from the following files: