Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 338 of file qmetaobject.h.

Constructor & Destructor Documentation

◆ QMetaProperty()

QMetaProperty::QMetaProperty ( )
inlineconstexpr

Definition at line 341 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 4145 of file qmetaobject.cpp.

◆ enclosingMetaObject()

const QMetaObject * QMetaProperty::enclosingMetaObject ( ) const
inline

Definition at line 396 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 3997 of file qmetaobject.cpp.

◆ 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 4237 of file qmetaobject.cpp.

◆ 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 3914 of file qmetaobject.cpp.

◆ 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 3928 of file qmetaobject.cpp.

◆ 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 4430 of file qmetaobject.cpp.

◆ 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 4386 of file qmetaobject.cpp.

◆ 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 4327 of file qmetaobject.cpp.

◆ 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 3898 of file qmetaobject.cpp.

◆ 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 4400 of file qmetaobject.cpp.

◆ 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 3887 of file qmetaobject.cpp.

◆ isReadable()

bool QMetaProperty::isReadable ( ) const

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

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

Definition at line 4224 of file qmetaobject.cpp.

◆ 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 4414 of file qmetaobject.cpp.

◆ 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 4212 of file qmetaobject.cpp.

◆ 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 4340 of file qmetaobject.cpp.

◆ 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 4357 of file qmetaobject.cpp.

◆ 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 4372 of file qmetaobject.cpp.

◆ isValid()

bool QMetaProperty::isValid ( ) const
inline

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

See also
isReadable()

Definition at line 395 of file qmetaobject.h.

◆ isWritable()

bool QMetaProperty::isWritable ( ) const

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

See also
isReadable(), write()

Definition at line 4314 of file qmetaobject.cpp.

◆ metaType()

QMetaType QMetaProperty::metaType ( ) const
Since
6.0

Returns this property's QMetaType.

See also
QMetaType

Definition at line 3838 of file qmetaobject.cpp.

◆ name()

const char * QMetaProperty::name ( ) const

Returns this property's name.

See also
type(), typeName()

Definition at line 3780 of file qmetaobject.cpp.

◆ 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 4252 of file qmetaobject.cpp.

◆ 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 4269 of file qmetaobject.cpp.

◆ propertyIndex()

int QMetaProperty::propertyIndex ( ) const
Since
4.6

Returns this property's index.

Definition at line 3858 of file qmetaobject.cpp.

◆ 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 4008 of file qmetaobject.cpp.

◆ 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 4160 of file qmetaobject.cpp.

◆ relativePropertyIndex()

int QMetaProperty::relativePropertyIndex ( ) const
Since
5.14

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

Definition at line 3870 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 4124 of file qmetaobject.cpp.

◆ 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 4200 of file qmetaobject.cpp.

◆ revision()

int QMetaProperty::revision ( ) const
Since
5.1

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

Definition at line 4301 of file qmetaobject.cpp.

◆ 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 354 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 3792 of file qmetaobject.cpp.

◆ 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 353 of file qmetaobject.h.

◆ 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 4057 of file qmetaobject.cpp.

◆ 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 4068 of file qmetaobject.cpp.

◆ 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 4174 of file qmetaobject.cpp.

◆ 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 4184 of file qmetaobject.cpp.

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 424 of file qmetaobject.h.

◆ QMetaObjectPrivate

friend struct QMetaObjectPrivate
friend

Definition at line 425 of file qmetaobject.h.


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