![]() |
Qt 6.x
The Qt SDK
|
The QQmlProperty class abstracts accessing properties on objects created from QML. More...
#include <qqmlproperty.h>
Public Types | |
enum | PropertyTypeCategory { InvalidCategory , List , Object , Normal } |
This enum specifies a category of QML property. More... | |
enum | Type { Invalid , Property , SignalProperty } |
This enum specifies a type of QML property. More... | |
Public Member Functions | |
QQmlProperty () | |
Create an invalid QQmlProperty. | |
~QQmlProperty () | |
QQmlProperty (QObject *) | |
Creates a QQmlProperty for the default property of obj. | |
QQmlProperty (QObject *, QQmlContext *) | |
Creates a QQmlProperty for the default property of obj using the \l{QQmlContext} {context} ctxt. | |
QQmlProperty (QObject *, QQmlEngine *) | |
Creates a QQmlProperty for the default property of obj using the environment for instantiating QML components that is provided by engine. | |
QQmlProperty (QObject *, const QString &) | |
Creates a QQmlProperty for the property name of obj. | |
QQmlProperty (QObject *, const QString &, QQmlContext *) | |
Creates a QQmlProperty for the property name of obj using the \l{QQmlContext} {context} ctxt. | |
QQmlProperty (QObject *, const QString &, QQmlEngine *) | |
Creates a QQmlProperty for the property name of obj using the environment for instantiating QML components that is provided by engine. | |
QQmlProperty (const QQmlProperty &) | |
Create a copy of other. | |
QQmlProperty & | operator= (const QQmlProperty &) |
Assign other to this QQmlProperty. | |
QQmlProperty (QQmlProperty &&other) noexcept | |
void | swap (QQmlProperty &other) noexcept |
bool | operator== (const QQmlProperty &) const |
Returns true if other and this QQmlProperty represent the same property. | |
Type | type () const |
Returns the type of the property. | |
bool | isValid () const |
Returns true if the QQmlProperty refers to a valid property, otherwise false. | |
bool | isProperty () const |
Returns true if this QQmlProperty represents a regular Qt property. | |
bool | isSignalProperty () const |
Returns true if this QQmlProperty represents a QML signal property. | |
int | propertyType () const |
Returns the metatype id of the property, or QMetaType::UnknownType if the property has no metatype. | |
QMetaType | propertyMetaType () const |
Returns the metatype of the property. | |
PropertyTypeCategory | propertyTypeCategory () const |
Returns the property category. | |
const char * | propertyTypeName () const |
Returns the type name of the property, or 0 if the property has no type name. | |
QString | name () const |
Return the name of this QML property. | |
QVariant | read () const |
Returns the property value. | |
bool | write (const QVariant &) const |
Sets the property value to value. | |
bool | reset () const |
Resets the property and returns true if the property is resettable. | |
bool | hasNotifySignal () const |
Returns true if the property has a change notifier signal, otherwise false. | |
bool | needsNotifySignal () const |
Returns true if the property needs a change notifier signal for bindings to remain upto date, false otherwise. | |
bool | connectNotifySignal (QObject *dest, const char *slot) const |
Connects the property's change notifier signal to the specified slot of the dest object and returns true. | |
bool | connectNotifySignal (QObject *dest, int method) const |
Connects the property's change notifier signal to the specified method of the dest object and returns true. | |
bool | isWritable () const |
Returns true if the property is writable, otherwise false. | |
bool | isBindable () const |
bool | isDesignable () const |
Returns true if the property is designable, otherwise false. | |
bool | isResettable () const |
Returns true if the property is resettable, otherwise false. | |
QObject * | object () const |
Returns the QQmlProperty's QObject. | |
int | index () const |
Return the Qt metaobject index of the property. | |
QMetaProperty | property () const |
Returns the \l{QMetaProperty} {Qt property} associated with this QML property. | |
QMetaMethod | method () const |
Return the QMetaMethod for this property if it is a SignalProperty, otherwise returns an invalid QMetaMethod. | |
Static Public Member Functions | |
static QVariant | read (const QObject *, const QString &) |
Return the name property value of object. | |
static QVariant | read (const QObject *, const QString &, QQmlContext *) |
Return the name property value of object using the \l{QQmlContext} {context} ctxt. | |
static QVariant | read (const QObject *, const QString &, QQmlEngine *) |
Return the name property value of object using the environment for instantiating QML components that is provided by engine. | |
static bool | write (QObject *, const QString &, const QVariant &) |
Writes value to the name property of object. | |
static bool | write (QObject *, const QString &, const QVariant &, QQmlContext *) |
Writes value to the name property of object using the \l{QQmlContext} {context} ctxt. | |
static bool | write (QObject *, const QString &, const QVariant &, QQmlEngine *) |
Writes value to the name property of object using the environment for instantiating QML components that is provided by engine. | |
Properties | |
QML_ANONYMOUSQObject * | object |
QString | name |
Friends | |
class | QQmlPropertyPrivate |
The QQmlProperty class abstracts accessing properties on objects created from QML.
As QML uses Qt's meta-type system all of the existing QMetaObject classes can be used to introspect and interact with objects created by QML. However, some of the new features provided by QML - such as type safety and attached properties - are most easily used through the QQmlProperty class that simplifies some of their natural complexity.
Unlike QMetaProperty which represents a property on a class type, QQmlProperty encapsulates a property on a specific object instance. To read a property's value, programmers create a QQmlProperty instance and call the read() method. Likewise to write a property value the write() method is used.
For example, for the following QML code:
\qml MyItem.qml import QtQuick 2.0
Text { text: "A bit of text" } \endqml
The \l Text object's properties could be accessed using QQmlProperty, like this:
Definition at line 22 of file qqmlproperty.h.
This enum specifies a category of QML property.
\value InvalidCategory The property is invalid, or is a signal property. \value List The property is a QQmlListProperty list property \value Object The property is a QObject derived type pointer \value Normal The property is a normal value property.
Enumerator | |
---|---|
InvalidCategory | |
List | |
Object | |
Normal |
Definition at line 31 of file qqmlproperty.h.
enum QQmlProperty::Type |
This enum specifies a type of QML property.
\value Invalid The property is invalid. \value Property The property is a regular Qt property. \value SignalProperty The property is a signal property.
Enumerator | |
---|---|
Invalid | |
Property | |
SignalProperty |
Definition at line 38 of file qqmlproperty.h.
|
default |
Create an invalid QQmlProperty.
QQmlProperty::~QQmlProperty | ( | ) |
Definition at line 85 of file qqmlproperty.cpp.
References QQmlRefCounted< T >::release().
QQmlProperty::QQmlProperty | ( | QObject * | obj | ) |
Creates a QQmlProperty for the default property of obj.
If there is no default property, an invalid QQmlProperty will be created.
Definition at line 96 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::initDefault().
QQmlProperty::QQmlProperty | ( | QObject * | obj, |
QQmlContext * | ctxt | ||
) |
Creates a QQmlProperty for the default property of obj using the \l{QQmlContext} {context} ctxt.
If there is no default property, an invalid QQmlProperty will be created.
Definition at line 108 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::context, QQmlContext::engine(), QQmlPropertyPrivate::engine, QQmlContextData::get(), and QQmlPropertyPrivate::initDefault().
QQmlProperty::QQmlProperty | ( | QObject * | obj, |
QQmlEngine * | engine | ||
) |
Creates a QQmlProperty for the default property of obj using the environment for instantiating QML components that is provided by engine.
If there is no default property, an invalid QQmlProperty will be created.
Definition at line 124 of file qqmlproperty.cpp.
References engine, QQmlPropertyPrivate::engine, and QQmlPropertyPrivate::initDefault().
Creates a QQmlProperty for the property name of obj.
Definition at line 148 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::initProperty(), isValid(), and QQmlPropertyPrivate::object.
QQmlProperty::QQmlProperty | ( | QObject * | obj, |
const QString & | name, | ||
QQmlContext * | ctxt | ||
) |
Creates a QQmlProperty for the property name of obj using the \l{QQmlContext} {context} ctxt.
Creating a QQmlProperty without a context will render some properties - like attached properties - inaccessible.
Definition at line 162 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::context, QQmlContext::engine(), QQmlPropertyPrivate::engine, QQmlContextData::get(), QQmlPropertyPrivate::initProperty(), isValid(), QQmlPropertyPrivate::object, and QQmlRefPointer< T >::reset().
QQmlProperty::QQmlProperty | ( | QObject * | obj, |
const QString & | name, | ||
QQmlEngine * | engine | ||
) |
Creates a QQmlProperty for the property name of obj using the environment for instantiating QML components that is provided by engine.
Definition at line 183 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::context, engine, QQmlPropertyPrivate::engine, QQmlPropertyPrivate::initProperty(), isValid(), QQmlPropertyPrivate::object, and QQmlRefPointer< T >::reset().
QQmlProperty::QQmlProperty | ( | const QQmlProperty & | other | ) |
Create a copy of other.
Definition at line 475 of file qqmlproperty.cpp.
References QQmlRefCount::addref(), and other().
|
inlinenoexcept |
Definition at line 58 of file qqmlproperty.h.
bool QQmlProperty::connectNotifySignal | ( | QObject * | dest, |
const char * | slot | ||
) | const |
Connects the property's change notifier signal to the specified slot of the dest object and returns true.
Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified slot.
Definition at line 1897 of file qqmlproperty.cpp.
References QObject::connect(), QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QMetaProperty::hasNotifySignal(), QMetaMethod::methodSignature(), QMetaProperty::notifySignal(), QQmlPropertyPrivate::object, QObject::property(), Property, signal, and type().
bool QQmlProperty::connectNotifySignal | ( | QObject * | dest, |
int | method | ||
) | const |
Connects the property's change notifier signal to the specified method of the dest object and returns true.
Returns false if this metaproperty does not represent a regular Qt property or if it has no change notifier signal, or if the dest object does not have the specified method.
Definition at line 1873 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::connect(), QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), Qt::DirectConnection, QMetaProperty::hasNotifySignal(), method(), QMetaProperty::notifySignalIndex(), QQmlPropertyPrivate::object, QObject::property(), Property, and type().
bool QQmlProperty::hasNotifySignal | ( | ) | const |
Returns true if the property has a change notifier signal, otherwise false.
Definition at line 1845 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyPrivate::object, QObject::property(), Property, and type().
int QQmlProperty::index | ( | ) | const |
Return the Qt metaobject index of the property.
Definition at line 1914 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, and QQmlPropertyData::coreIndex().
Referenced by QQDMIncubationTask::initializeRequiredProperties(), QQmlComponentPrivate::setInitialProperty(), and QQmlBindEntry::setTarget().
bool QQmlProperty::isBindable | ( | ) | const |
Returns true if the property is bindable, otherwise false.
Definition at line 682 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::isBindable(), QQmlPropertyData::isValid(), and QQmlPropertyPrivate::object.
Referenced by QQmlAnyBinding::createFromCodeString(), QQmlAnyBinding::createFromFunction(), QQmlAnyBinding::createFromScriptString(), QQmlAnyBinding::ofProperty(), QQmlAnyBinding::removeBindingFrom(), QQmlComponentPrivate::setInitialProperty(), and QQmlAnyBinding::takeFrom().
bool QQmlProperty::isDesignable | ( | ) | const |
Returns true if the property is designable, otherwise false.
Definition at line 696 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyData::isValid(), QQmlPropertyPrivate::object, QObject::property(), Property, and type().
bool QQmlProperty::isProperty | ( | ) | const |
Returns true if this QQmlProperty represents a regular Qt property.
Definition at line 628 of file qqmlproperty.cpp.
References Property, and type().
Referenced by QQmlPropertyPrivate::binding(), QQmlPropertyPrivate::removeBinding(), and QQmlPropertyPrivate::setBinding().
bool QQmlProperty::isResettable | ( | ) | const |
Returns true if the property is resettable, otherwise false.
Definition at line 709 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::isResettable(), QQmlPropertyData::isValid(), QQmlPropertyPrivate::object, Property, and type().
Referenced by reset().
bool QQmlProperty::isSignalProperty | ( | ) | const |
Returns true if this QQmlProperty represents a QML signal property.
Definition at line 636 of file qqmlproperty.cpp.
References SignalProperty, and type().
Referenced by QQuickPropertyChangesPrivate::decodeBinding().
bool QQmlProperty::isValid | ( | ) | const |
Returns true if the QQmlProperty refers to a valid property, otherwise false.
Definition at line 723 of file qqmlproperty.cpp.
References Invalid, and type().
Referenced by QQmlProperty(), QQmlProperty(), QQmlProperty(), QQuickStateAction::QQuickStateAction(), QQuickStateAction::QQuickStateAction(), QQuickPropertyChanges::actions(), QQuickDesignerSupportProperties::allPropertyNames(), QQuickDesignerSupport::anchorLineTarget(), QQuickAbstractAnimationPrivate::createProperty(), QQmlBindPrivate::decodeBinding(), QQmlIncubatorPrivate::incubate(), QQuickPropertyChangesPrivate::property(), propertyNameListForWritableProperties(), QQmlComponentPrivate::removePropertyFromRequired(), QQmlComponentPrivate::setInitialProperty(), QQuickImageSelector::setSource(), and QQmlBindPrivate::validate().
bool QQmlProperty::isWritable | ( | ) | const |
Returns true if the property is writable, otherwise false.
Definition at line 662 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::isFunction(), QQmlPropertyData::isQList(), QQmlPropertyData::isValid(), QQmlPropertyData::isWritable(), and QQmlPropertyPrivate::object.
Referenced by QQuickAbstractAnimationPrivate::createProperty(), QQuickPropertyChangesPrivate::property(), propertyNameListForWritableProperties(), QQmlBindEntry::validate(), and QQmlPropertyPrivate::write().
QMetaMethod QQmlProperty::method | ( | ) | const |
Return the QMetaMethod for this property if it is a SignalProperty, otherwise returns an invalid QMetaMethod.
Definition at line 782 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyPrivate::object, SignalProperty, and type().
Referenced by connectNotifySignal().
QString QQmlProperty::name | ( | ) | const |
Return the name of this QML property.
Definition at line 733 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QString::fromUtf8(), i, QString::isEmpty(), QQmlPropertyPrivate::isValueType(), QQmlMetaType::metaObjectForValueType(), QMetaProperty::name(), name, QQmlPropertyData::name(), QQmlPropertyPrivate::nameCache, QQmlPropertyPrivate::object, QMetaObject::property(), QQmlPropertyData::propType(), Q_ASSERT, QStringLiteral, SignalProperty, QChar::toUpper(), type(), and QQmlPropertyPrivate::valueTypeData.
bool QQmlProperty::needsNotifySignal | ( | ) | const |
Returns true if the property needs a change notifier signal for bindings to remain upto date, false otherwise.
Some properties, such as attached properties or those whose value never changes, do not require a change notifier.
Definition at line 1860 of file qqmlproperty.cpp.
References QMetaProperty::isConstant(), Property, property(), and type().
QObject * QQmlProperty::object | ( | ) | const |
Returns the QQmlProperty's QObject.
Definition at line 644 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::object.
QQmlProperty & QQmlProperty::operator= | ( | const QQmlProperty & | other | ) |
Assign other to this QQmlProperty.
Definition at line 652 of file qqmlproperty.cpp.
References other(), and qSwap().
bool QQmlProperty::operator== | ( | const QQmlProperty & | other | ) | const |
Returns true if other and this QQmlProperty represent the same property.
Definition at line 558 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyPrivate::object, other(), and QQmlPropertyPrivate::valueTypeData.
QMetaProperty QQmlProperty::property | ( | ) | const |
Returns the \l{QMetaProperty} {Qt property} associated with this QML property.
Definition at line 768 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyData::isValid(), QQmlPropertyPrivate::object, QObject::property(), Property, and type().
Referenced by QQuickSimpleAction::QQuickSimpleAction(), QQuickPropertyChanges::actions(), needsNotifySignal(), QQmlAnyBinding::ofProperty(), QQuickState::removeAllEntriesFromRevertList(), QQmlAnyBinding::removeBindingFrom(), and QQmlAnyBinding::takeFrom().
QMetaType QQmlProperty::propertyMetaType | ( | ) | const |
Returns the metatype of the property.
Definition at line 585 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::propertyType().
int QQmlProperty::propertyType | ( | ) | const |
Returns the metatype id of the property, or QMetaType::UnknownType if the property has no metatype.
Definition at line 575 of file qqmlproperty.cpp.
References QMetaType::id(), QQmlPropertyPrivate::propertyType(), and QMetaType::UnknownType.
Referenced by QQuickPropertyAnimation::createTransitionActions(), and QQuickAnimationPropertyUpdater::setValue().
QQmlProperty::PropertyTypeCategory QQmlProperty::propertyTypeCategory | ( | ) | const |
Returns the property category.
Definition at line 506 of file qqmlproperty.cpp.
References InvalidCategory, and QQmlPropertyPrivate::propertyTypeCategory().
Referenced by QQuickDesignerSupportProperties::allPropertyNames(), and propertyNameListForWritableProperties().
const char * QQmlProperty::propertyTypeName | ( | ) | const |
Returns the type name of the property, or 0 if the property has no type name.
Definition at line 539 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), QQmlPropertyData::isValid(), QQmlPropertyPrivate::isValueType(), QQmlMetaType::metaObjectForValueType(), QQmlPropertyPrivate::object, QObject::property(), QMetaObject::property(), Property, QQmlPropertyData::propType(), Q_ASSERT, QMetaProperty::typeName(), QVariant::typeName(), and QQmlPropertyPrivate::valueTypeData.
QVariant QQmlProperty::read | ( | ) | const |
Returns the property value.
Definition at line 1062 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::object, Property, QQmlPropertyPrivate::readValueProperty(), SignalProperty, and type().
Referenced by QQuickParentChange::actions(), QQuickDesignerSupportProperties::allPropertyNames(), QQuickDesignerSupport::anchorLineTarget(), QQuickAnimatorPrivate::apply(), QQuickPropertyChanges::changeExpression(), QQuickPropertyChanges::changeValue(), QQuickImageSelector::componentComplete(), main(), propertyNameListForWritableProperties(), QQuickAnimationPropertyUpdater::setValue(), and QQuickTransitionManager::transition().
Return the name property value of object.
This method is equivalent to:
Definition at line 1088 of file qqmlproperty.cpp.
|
static |
Return the name property value of object using the \l{QQmlContext} {context} ctxt.
This method is equivalent to:
Definition at line 1104 of file qqmlproperty.cpp.
|
static |
Return the name property value of object using the environment for instantiating QML components that is provided by engine.
This method is equivalent to:
Definition at line 1121 of file qqmlproperty.cpp.
References engine.
bool QQmlProperty::reset | ( | ) | const |
Resets the property and returns true if the property is resettable.
If the property is not resettable, nothing happens and false is returned.
Definition at line 1819 of file qqmlproperty.cpp.
References args, QQmlPropertyPrivate::core, QQmlPropertyData::coreIndex(), isResettable(), QMetaObject::metacall(), QQmlPropertyPrivate::object, and QMetaObject::ResetProperty.
|
inlinenoexcept |
Definition at line 61 of file qqmlproperty.h.
References d, other(), and qt_ptr_swap().
QQmlProperty::Type QQmlProperty::type | ( | ) | const |
Returns the type of the property.
Definition at line 620 of file qqmlproperty.cpp.
References Invalid, and QQmlPropertyPrivate::type().
Referenced by connectNotifySignal(), connectNotifySignal(), hasNotifySignal(), isDesignable(), isProperty(), isResettable(), isSignalProperty(), isValid(), method(), name(), needsNotifySignal(), property(), QQuickPropertyChangesPrivate::property(), read(), QQmlPropertyPrivate::signalExpression(), QQmlPropertyPrivate::takeSignalExpression(), and QQmlPropertyPrivate::write().
bool QQmlProperty::write | ( | const QVariant & | value | ) | const |
Sets the property value to value.
Returns true
on success, or false
if the property can't be set because the value is the wrong type, for example.
Definition at line 1751 of file qqmlproperty.cpp.
References QQmlPropertyPrivate::write().
Referenced by QQuickPopupPrivate::hideOverlay(), QQmlIncubatorPrivate::incubate(), main(), QQuickState::removeEntryFromRevertList(), QQmlTableInstanceModel::setRequiredProperty(), and QQuickPopupPrivate::showOverlay().
Writes value to the name property of object.
This method is equivalent to:
Returns true
on success, false
otherwise.
Definition at line 1767 of file qqmlproperty.cpp.
|
static |
Writes value to the name property of object using the \l{QQmlContext} {context} ctxt.
This method is equivalent to:
Returns true
on success, false
otherwise.
Definition at line 1785 of file qqmlproperty.cpp.
|
static |
Writes value to the name property of object using the environment for instantiating QML components that is provided by engine.
This method is equivalent to:
Returns true
on success, false
otherwise.
Definition at line 1807 of file qqmlproperty.cpp.
References engine.
|
friend |
Definition at line 104 of file qqmlproperty.h.
|
read |
Definition at line 25 of file qqmlproperty.h.
Referenced by QQuickDesignerSupportProperties::allPropertyNames(), QQuickAnimatorPrivate::apply(), QQuickPropertyAnimation::createTransitionActions(), QQuickAnimationPropertyUpdater::debugUpdater(), name(), QQmlAbstractBinding::printBindingLoopError(), propertyNameListForWritableProperties(), QQuickState::removeEntryFromRevertList(), QQuickPropertyAction::transition(), and QQmlBindEntry::validate().
|
read |
Definition at line 25 of file qqmlproperty.h.
Referenced by QQuickAnimatorPrivate::apply(), QQmlAnyBinding::createFromCodeString(), QQmlAnyBinding::createFromFunction(), QQmlAnyBinding::createFromScriptString(), QQuickPropertyAnimation::createTransitionActions(), QQuickAnimationPropertyUpdater::debugUpdater(), QQuickPropertyChangesPrivate::decodeBinding(), QQDMIncubationTask::initializeRequiredProperties(), QQmlAnyBinding::ofProperty(), QQmlAbstractBinding::printBindingLoopError(), QQmlAnyBinding::removeBindingFrom(), QQuickState::removeEntryFromRevertList(), QQmlComponentPrivate::setInitialProperty(), QQmlAbstractBinding::setTarget(), QQmlBindEntry::setTarget(), QQmlAnyBinding::takeFrom(), QQuickPropertyAction::transition(), and QQmlBindEntry::validate().