
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQDeclarativeProperty class abstracts accessing properties on objects created from QML.More...
| Header: | #include <QDeclarativeProperty> |
| Since: | Qt 4.7 |
| enum | PropertyTypeCategory { InvalidCategory, List, Object, Normal } |
| enum | Type { Invalid, Property, SignalProperty } |
| QDeclarativeProperty() | |
| QDeclarativeProperty(QObject * obj) | |
| QDeclarativeProperty(QObject * obj, QDeclarativeContext * ctxt) | |
| QDeclarativeProperty(QObject * obj, QDeclarativeEngine * engine) | |
| QDeclarativeProperty(QObject * obj, const QString & name) | |
| QDeclarativeProperty(QObject * obj, const QString & name, QDeclarativeContext * ctxt) | |
| QDeclarativeProperty(QObject * obj, const QString & name, QDeclarativeEngine * engine) | |
| QDeclarativeProperty(const QDeclarativeProperty & 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 |
| PropertyTypeCategory | propertyTypeCategory() const |
| const char * | propertyTypeName() const |
| QVariant | read() const |
| bool | reset() const |
| Type | type() const |
| bool | write(const QVariant & value) const |
| QDeclarativeProperty & | operator=(const QDeclarativeProperty & other) |
| bool | operator==(const QDeclarativeProperty & other) const |
| QVariant | read(QObject * object, const QString & name) |
| QVariant | read(QObject * object, const QString & name, QDeclarativeContext * ctxt) |
| QVariant | read(QObject * object, const QString & name, QDeclarativeEngine * engine) |
| bool | write(QObject * object, const QString & name, const QVariant & value) |
| bool | write(QObject * object, const QString & name, const QVariant & value, QDeclarativeContext * ctxt) |
| bool | write(QObject * object, const QString & name, const QVariant & value, QDeclarativeEngine * engine) |
TheQDeclarativeProperty class abstracts accessing properties on objects created from QML.
As QML uses Qt's meta-type system all of the existingQMetaObject 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 theQDeclarativeProperty class that simplifies some of their natural complexity.
UnlikeQMetaProperty which represents a property on a class type,QDeclarativeProperty encapsulates a property on a specific object instance. To read a property's value, programmers create aQDeclarativeProperty instance and call theread() method. Likewise to write a property value thewrite() method is used.
For example, for the following QML code:
// MyItem.qmlimport QtQuick 1.0Text {text:"A bit of text" }
TheText object's properties could be accessed usingQDeclarativeProperty, like this:
#include <QDeclarativeProperty>#include <QGraphicsObject>...QDeclarativeView view(QUrl::fromLocalFile("MyItem.qml"));QDeclarativePropertyproperty(view.rootObject(),"font.pixelSize");qWarning()<<"Current pixel size:"<< property.read().toInt();property.write(24);qWarning()<<"Pixel size should now be 24:"<< property.read().toInt();
This enum specifies a category of QML property.
| Constant | Value | Description |
|---|---|---|
QDeclarativeProperty::InvalidCategory | 0 | The property is invalid, or is a signal property. |
QDeclarativeProperty::List | 1 | The property is aQDeclarativeListProperty list property |
QDeclarativeProperty::Object | 2 | The property is aQObject derived type pointer |
QDeclarativeProperty::Normal | 3 | The property is a normal value property. |
This enum specifies a type of QML property.
| Constant | Value | Description |
|---|---|---|
QDeclarativeProperty::Invalid | 0 | The property is invalid. |
QDeclarativeProperty::Property | 1 | The property is a regular Qt property. |
QDeclarativeProperty::SignalProperty | 2 | The property is a signal property. |
Create an invalidQDeclarativeProperty.
Creates aQDeclarativeProperty for the default property ofobj. If there is no default property, an invalidQDeclarativeProperty will be created.
Creates aQDeclarativeProperty for the default property ofobj using thecontextctxt. If there is no default property, an invalidQDeclarativeProperty will be created.
Creates aQDeclarativeProperty for the default property ofobj using the environment for instantiating QML components that is provided byengine. If there is no default property, an invalidQDeclarativeProperty will be created.
Creates aQDeclarativeProperty for the propertyname ofobj.
Creates aQDeclarativeProperty for the propertyname ofobj using thecontextctxt.
Creating aQDeclarativeProperty without a context will render some properties - like attached properties - inaccessible.
Creates aQDeclarativeProperty for the propertyname ofobj using the environment for instantiating QML components that is provided byengine.
Create a copy ofother.
Connects the property's change notifier signal to the specifiedslot of thedest 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 thedest object does not have the specifiedslot.
Connects the property's change notifier signal to the specifiedmethod of thedest 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 thedest object does not have the specifiedmethod.
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 thisQDeclarativeProperty represents a regular Qt property.
Returns true if the property is resettable, otherwise false.
Returns true if thisQDeclarativeProperty represents a QML signal property.
Returns true if theQDeclarativeProperty refers to a valid property, otherwise false.
Returns true if the property is writable, otherwise false.
Return theQMetaMethod for this property if it is aSignalProperty, otherwise returns an invalidQMetaMethod.
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 theQDeclarativeProperty'sQObject.
Returns theQt property associated with this QML property.
Returns theQVariant type of the property, orQVariant::Invalid if the property has noQVariant 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 QDeclarativeProperty::read(QObject * object, constQString & name)Return thename property value ofobject. This method is equivalent to:
QDeclarativeProperty p(object, name);p.read();
[static]QVariant QDeclarativeProperty::read(QObject * object, constQString & name,QDeclarativeContext * ctxt)Return thename property value ofobject using thecontextctxt. This method is equivalent to:
QDeclarativeProperty p(object, name, context);p.read();
[static]QVariant QDeclarativeProperty::read(QObject * object, constQString & name,QDeclarativeEngine * engine)Return thename property value ofobject using the environment for instantiating QML components that is provided byengine. . This method is equivalent to:
QDeclarativeProperty 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 tovalue and returns true. Returns false if the property can't be set because thevalue is the wrong type, for example.
[static]bool QDeclarativeProperty::write(QObject * object, constQString & name, constQVariant & value)Writesvalue to thename property ofobject. This method is equivalent to:
QDeclarativeProperty p(object, name);p.write(value);
[static]bool QDeclarativeProperty::write(QObject * object, constQString & name, constQVariant & value,QDeclarativeContext * ctxt)Writesvalue to thename property ofobject using thecontextctxt. This method is equivalent to:
QDeclarativeProperty p(object, name, ctxt);p.write(value);
[static]bool QDeclarativeProperty::write(QObject * object, constQString & name, constQVariant & value,QDeclarativeEngine * engine)Writesvalue to thename property ofobject using the environment for instantiating QML components that is provided byengine. This method is equivalent to:
QDeclarativeProperty p(object, name, engine);p.write(value);
Assignother to thisQDeclarativeProperty.
Returns true ifother and thisQDeclarativeProperty represent the same property.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.