The QQmlProperty class abstracts accessing properties on objects created from QML. More...
Header: | #include <QQmlProperty> |
qmake: | QT += qml |
Since: | Qt 5.0 |
enum | PropertyTypeCategory { InvalidCategory, List, Object, Normal } |
enum | Type { Invalid, Property, SignalProperty } |
QQmlProperty() | |
QQmlProperty(QObject *obj) | |
QQmlProperty(QObject *obj, QQmlContext *ctxt) | |
QQmlProperty(QObject *obj, QQmlEngine *engine) | |
QQmlProperty(QObject *obj, const QString &name) | |
QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt) | |
QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine) | |
QQmlProperty(const QQmlProperty &other) | |
bool | connectNotifySignal(QObject *dest, const char *slot) const |
bool | connectNotifySignal(QObject *dest, int method) const |
bool | hasNotifySignal() const |
int | index() const |
bool | isDesignable() const |
bool | isProperty() const |
bool | isResettable() const |
bool | isSignalProperty() const |
bool | isValid() const |
bool | isWritable() const |
QMetaMethod | method() const |
QString | name() const |
bool | needsNotifySignal() const |
QObject * | object() const |
QMetaProperty | property() const |
int | propertyType() const |
QQmlProperty::PropertyTypeCategory | propertyTypeCategory() const |
const char * | propertyTypeName() const |
QVariant | read() const |
bool | reset() const |
QQmlProperty::Type | type() const |
bool | write(const QVariant &value) const |
QQmlProperty & | operator=(const QQmlProperty &other) |
bool | operator==(const QQmlProperty &other) const |
QVariant | read(const QObject *object, const QString &name) |
QVariant | read(const QObject *object, const QString &name, QQmlContext *ctxt) |
QVariant | read(const QObject *object, const QString &name, QQmlEngine *engine) |
bool | write(QObject *object, const QString &name, const QVariant &value) |
bool | write(QObject *object, const QString &name, const QVariant &value, QQmlContext *ctxt) |
bool | write(QObject *object, const QString &name, const QVariant &value, QQmlEngine *engine) |
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:
// MyItem.qml import QtQuick 2.0 Text { text: "A bit of text" }
The Text object's properties could be accessed using QQmlProperty, like this:
#include <QQmlProperty> #include <QGraphicsObject> ... QQuickView view(QUrl::fromLocalFile("MyItem.qml")); QQmlProperty property(view.rootObject(), "font.pixelSize"); qWarning() << "Current pixel size:" << property.read().toInt(); property.write(24); qWarning() << "Pixel size should now be 24:" << property.read().toInt();
The Qt Quick 1 version of this class was named QDeclarativeProperty.
This enum specifies a category of QML property.
Constant | Value | Description |
---|---|---|
QQmlProperty::InvalidCategory |
0 |
The property is invalid, or is a signal property. |
QQmlProperty::List |
1 |
The property is a QQmlListProperty list property |
QQmlProperty::Object |
2 |
The property is a QObject derived type pointer |
QQmlProperty::Normal |
3 |
The property is a normal value property. |
This enum specifies a type of QML property.
Constant | Value | Description |
---|---|---|
QQmlProperty::Invalid |
0 |
The property is invalid. |
QQmlProperty::Property |
1 |
The property is a regular Qt property. |
QQmlProperty::SignalProperty |
2 |
The property is a signal property. |
Create an invalid QQmlProperty.
Creates a QQmlProperty for the default property of obj. If there is no default property, an invalid QQmlProperty will be created.
Creates a QQmlProperty for the default property of obj using the context ctxt. If there is no default property, an invalid QQmlProperty will be created.
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.
Creates a QQmlProperty for the property name of obj.
Creates a QQmlProperty for the property name of obj using the context ctxt.
Creating a QQmlProperty without a context will render some properties - like attached properties - inaccessible.
Creates a QQmlProperty for the property name of obj using the environment for instantiating QML components that is provided by engine.
Create a copy of other.
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.
Note: slot should be passed using the SLOT() macro so it is correctly identified.
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.
Returns true if the property has a change notifier signal, otherwise false.
Return the Qt metaobject index of the property.
Returns true if the property is designable, otherwise false.
Returns true if this QQmlProperty represents a regular Qt property.
Returns true if the property is resettable, otherwise false.
Returns true if this QQmlProperty represents a QML signal property.
Returns true if the QQmlProperty refers to a valid property, otherwise false.
Returns true if the property is writable, otherwise false.
Return the QMetaMethod for this property if it is a SignalProperty, otherwise returns an invalid QMetaMethod.
Return the name of this QML property.
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.
Returns the QQmlProperty's QObject.
Returns the Qt property associated with this QML property.
Returns the QVariant type of the property, or QVariant::Invalid if the property has no QVariant type.
Returns the property category.
Returns the type name of the property, or 0 if the property has no type name.
Returns the property value.
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name)Return the name property value of object. This method is equivalent to:
QQmlProperty p(object, name); p.read();
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlContext
*ctxt)Return the name property value of object using the context ctxt. This method is equivalent to:
QQmlProperty p(object, name, context); p.read();
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlEngine
*engine)Return the name property value of object using the environment for instantiating QML components that is provided by engine. . This method is equivalent to:
QQmlProperty p(object, name, engine); p.read();
Resets the property and returns true if the property is resettable. If the property is not resettable, nothing happens and false is returned.
Returns the type of the property.
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.
[static]
bool QQmlProperty::write(QObject
*object, const QString &name, const QVariant &value)Writes value to the name property of object. This method is equivalent to:
QQmlProperty p(object, name); p.write(value);
Returns true
on success, false
otherwise.
[static]
bool QQmlProperty::write(QObject
*object, const QString &name, const QVariant &value, QQmlContext *ctxt)Writes value to the name property of object using the context ctxt. This method is equivalent to:
QQmlProperty p(object, name, ctxt); p.write(value);
Returns true
on success, false
otherwise.
[static]
bool QQmlProperty::write(QObject
*object, const QString &name, const QVariant &value, QQmlEngine *engine)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:
QQmlProperty p(object, name, engine); p.write(value);
Returns true
on success, false
otherwise.
Assign other to this QQmlProperty.
Returns true if other and this QQmlProperty represent the same property.