QQmlProperty Class

The QQmlProperty class abstracts accessing properties on objects created from QML. 更多...

头: #include <QQmlProperty>
CMake: find_package(Qt6 COMPONENTS Qml REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
Since: Qt 5.0

公共类型

enum PropertyTypeCategory { InvalidCategory, List, Object, Normal }
enum Type { Invalid, Property, SignalProperty }

公共函数

  QQmlProperty (const QQmlProperty & other )
  QQmlProperty (QObject * obj , const QString & name , QQmlEngine * engine )
  QQmlProperty (QObject * obj , const QString & name , QQmlContext * ctxt )
  QQmlProperty (QObject * obj , const QString & name )
  QQmlProperty (QObject * obj , QQmlEngine * engine )
  QQmlProperty (QObject * obj , QQmlContext * ctxt )
  QQmlProperty (QObject * obj )
  QQmlProperty ()
QQmlProperty & operator= (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 方法 () const
QString name () const
bool needsNotifySignal () const
QObject * 对象 () const
QMetaProperty property () const
QMetaType propertyMetaType () 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
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 )

详细描述

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.

不像 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" }
					

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

成员类型文档编制

enum QQmlProperty:: PropertyTypeCategory

This enum specifies a category of QML property.

常量 描述
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.

enum QQmlProperty:: Type

This enum specifies a type of QML property.

常量 描述
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.

成员函数文档编制

QQmlProperty:: QQmlProperty (const QQmlProperty & other )

Create a copy of other .

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 .

QQmlProperty:: QQmlProperty ( QObject * obj , const QString & name , QQmlContext * ctxt )

Creates a QQmlProperty for the property name of obj 使用 context ctxt .

Creating a QQmlProperty without a context will render some properties - like attached properties - inaccessible.

QQmlProperty:: QQmlProperty ( QObject * obj , const QString & name )

Creates a QQmlProperty for the property name of obj .

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.

QQmlProperty:: QQmlProperty ( QObject * obj , QQmlContext * ctxt )

Creates a QQmlProperty for the default property of obj 使用 context ctxt . If there is no default property, an invalid QQmlProperty will be created.

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.

QQmlProperty:: QQmlProperty ()

Create an invalid QQmlProperty.

QQmlProperty &QQmlProperty:: operator= (const QQmlProperty & other )

赋值 other 到此 QQmlProperty .

bool QQmlProperty:: connectNotifySignal ( QObject * dest , const char * slot ) const

Connects the property's change notifier signal to the specified slot 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 .

注意: slot should be passed using the SLOT() macro so it is correctly identified.

bool QQmlProperty:: connectNotifySignal ( QObject * dest , int method ) const

Connects the property's change notifier signal to the specified method 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 .

bool QQmlProperty:: hasNotifySignal () const

Returns true if the property has a change notifier signal, otherwise false.

int QQmlProperty:: index () const

Return the Qt metaobject index of the property.

bool QQmlProperty:: isDesignable () const

Returns true if the property is designable, otherwise false.

bool QQmlProperty:: isProperty () const

返回 true,若此 QQmlProperty represents a regular Qt property.

bool QQmlProperty:: isResettable () const

Returns true if the property is resettable, otherwise false.

bool QQmlProperty:: isSignalProperty () const

返回 true,若此 QQmlProperty represents a QML signal property.

bool QQmlProperty:: isValid () const

返回 true 若 QQmlProperty refers to a valid property, otherwise false.

bool QQmlProperty:: isWritable () const

Returns true if the property is writable, otherwise false.

QMetaMethod QQmlProperty:: method () const

返回 QMetaMethod for this property if it is a SignalProperty , otherwise returns an invalid QMetaMethod .

QString QQmlProperty:: name () const

Return the name of this QML property.

注意: Getter function for property name.

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.

QObject *QQmlProperty:: 对象 () const

返回 QQmlProperty 's QObject .

注意: Getter function for property object.

QMetaProperty QQmlProperty:: property () const

返回 Qt 特性 associated with this QML property.

QMetaType QQmlProperty:: propertyMetaType () const

Returns the metatype of the property.

另请参阅 propertyType .

int QQmlProperty:: propertyType () const

Returns the metatype id of the property, or QMetaType::UnknownType if the property has no metatype.

另请参阅 propertyMetaType .

QQmlProperty::PropertyTypeCategory QQmlProperty:: propertyTypeCategory () const

Returns the property category.

const char *QQmlProperty:: propertyTypeName () const

Returns the type name of the property, or 0 if the property has no type name.

QVariant QQmlProperty:: read () const

Returns the property value.

[static] QVariant QQmlProperty:: read (const QObject * object , const QString & name )

返回 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 )

返回 name property value of object 使用 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 )

返回 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();
					

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.

QQmlProperty::Type QQmlProperty:: type () const

Returns the type of the property.

bool QQmlProperty:: write (const QVariant & value ) const

Sets the property value to value 。返回 true 当成功时,或 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 )

写入 valuename property of object . This method is equivalent to:

QQmlProperty p(object, name);
p.write(value);
					

返回 true 当成功时, false 否则。

[static] bool QQmlProperty:: write ( QObject * object , const QString & name , const QVariant & value , QQmlContext * ctxt )

写入 valuename property of object 使用 context ctxt . This method is equivalent to:

QQmlProperty p(object, name, ctxt);
p.write(value);
					

返回 true 当成功时, false 否则。

[static] bool QQmlProperty:: write ( QObject * object , const QString & name , const QVariant & value , QQmlEngine * engine )

写入 valuename 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);
					

返回 true 当成功时, false 否则。

bool QQmlProperty:: operator== (const QQmlProperty & other ) const

返回 true 若 other 和此 QQmlProperty represent the same property.