IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QMetaProperty Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QMetaProperty Class

  • Header: QMetaProperty

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QMetaProperty is part of objectmodel

Detailed Description

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

Member Function Documentation

 

[since 6.0] QUntypedBindable QMetaProperty::bindable(QObject *object) const

Returns the bindable interface for the property on a given object.

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

This function was introduced in Qt 6.0.

See Also

QMetaEnum QMetaProperty::enumerator() const

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

See Also

See also isEnumType(), isFlagType()

bool QMetaProperty::hasNotifySignal() const

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

See Also

See also notifySignal()

[since 6.0] bool QMetaProperty::isBindable() const

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.

This function was introduced in Qt 6.0.

See Also

See also QProperty, isWritable(), bindable()

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.

bool QMetaProperty::isDesignable() const

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

See Also

See also isScriptable(), isStored()

bool QMetaProperty::isEnumType() const

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

See Also

See also enumerator(), 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.

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

bool QMetaProperty::isReadable() const

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

See Also

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

[since 5.15] bool QMetaProperty::isRequired() const

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

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

This function was introduced in Qt 5.15.

bool QMetaProperty::isResettable() const

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

See Also

See also reset()

bool QMetaProperty::isScriptable() const

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

See Also

See also isDesignable(), 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

See also isDesignable(), 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

bool QMetaProperty::isValid() const

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

See Also

See also isReadable()

bool QMetaProperty::isWritable() const

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

See Also

See also isReadable(), write()

[since 6.0] QMetaType QMetaProperty::metaType() const

Returns this property's QMetaType.

This function was introduced in Qt 6.0.

See Also

See also QMetaType

const char *QMetaProperty::name() const

Returns this property's name.

See Also

See also type(), typeName()

QMetaMethod QMetaProperty::notifySignal() const

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

See Also

See also hasNotifySignal()

int QMetaProperty::notifySignalIndex() const

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

See Also

See also hasNotifySignal()

int QMetaProperty::propertyIndex() const

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

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

[since 5.5] 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.

[since 5.14] int QMetaProperty::relativePropertyIndex() const

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

This function was introduced in Qt 5.14.

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

See also read(), write()

[since 5.5] 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.

[since 5.1] 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.

[since 6.0] int QMetaProperty::typeId() const

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

This function was introduced in Qt 6.0.

See Also

See also QMetaType, typeName(), metaType()

const char *QMetaProperty::typeName() const

Returns the name of this property's type.

See Also

See also type(), name()

int QMetaProperty::userType() const

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

See also type(), QMetaType, typeName(), 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 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.

See Also

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

[since 5.5] 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.

Obsolete Members for QMetaProperty

The following members of class QMetaProperty are deprecated. We strongly advise against using them in new code.

Obsolete Member Function Documentation

 
QVariant::Type QMetaProperty::type() const

This function is deprecated. We strongly advise against using it in new code.

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

See Also

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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+