Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QQmlProperty Class Reference

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

#include <qqmlproperty.h>

+ Collaboration diagram for QQmlProperty:

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.
 
QQmlPropertyoperator= (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.
 
QObjectobject () 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
 

Detailed Description

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

Since
5.0 \inmodule QtQml

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:

#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 QQmlProperty class abstracts accessing properties on objects created from QML.
QMetaProperty property() const
Returns the \l{QMetaProperty} {Qt property} associated with this QML property.
QQuickItem * rootObject() const
Returns the view's root \l {QQuickItem} {item}.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3307
#define qWarning
Definition qlogging.h:167
QQuickView * view
[0]

Definition at line 22 of file qqmlproperty.h.

Member Enumeration Documentation

◆ PropertyTypeCategory

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 30 of file qqmlproperty.h.

◆ 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 37 of file qqmlproperty.h.

Constructor & Destructor Documentation

◆ QQmlProperty() [1/9]

QQmlProperty::QQmlProperty ( )
default

Create an invalid QQmlProperty.

◆ ~QQmlProperty()

QQmlProperty::~QQmlProperty ( )

Definition at line 87 of file qqmlproperty.cpp.

◆ QQmlProperty() [2/9]

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 98 of file qqmlproperty.cpp.

◆ QQmlProperty() [3/9]

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 110 of file qqmlproperty.cpp.

◆ QQmlProperty() [4/9]

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 126 of file qqmlproperty.cpp.

◆ QQmlProperty() [5/9]

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

Creates a QQmlProperty for the property name of obj.

Definition at line 150 of file qqmlproperty.cpp.

◆ QQmlProperty() [6/9]

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 164 of file qqmlproperty.cpp.

◆ QQmlProperty() [7/9]

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 185 of file qqmlproperty.cpp.

◆ QQmlProperty() [8/9]

QQmlProperty::QQmlProperty ( const QQmlProperty & other)

Create a copy of other.

Definition at line 484 of file qqmlproperty.cpp.

◆ QQmlProperty() [9/9]

QQmlProperty::QQmlProperty ( QQmlProperty && other)
inlinenoexcept

Definition at line 57 of file qqmlproperty.h.

Member Function Documentation

◆ connectNotifySignal() [1/2]

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.

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

Definition at line 1914 of file qqmlproperty.cpp.

◆ connectNotifySignal() [2/2]

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 1890 of file qqmlproperty.cpp.

◆ hasNotifySignal()

bool QQmlProperty::hasNotifySignal ( ) const

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

Definition at line 1862 of file qqmlproperty.cpp.

◆ index()

int QQmlProperty::index ( ) const

Return the Qt metaobject index of the property.

Definition at line 1931 of file qqmlproperty.cpp.

◆ isBindable()

bool QQmlProperty::isBindable ( ) const

Returns true if the property is bindable, otherwise false.

Definition at line 691 of file qqmlproperty.cpp.

◆ isDesignable()

bool QQmlProperty::isDesignable ( ) const

Returns true if the property is designable, otherwise false.

Definition at line 705 of file qqmlproperty.cpp.

◆ isProperty()

bool QQmlProperty::isProperty ( ) const

Returns true if this QQmlProperty represents a regular Qt property.

Definition at line 637 of file qqmlproperty.cpp.

◆ isResettable()

bool QQmlProperty::isResettable ( ) const

Returns true if the property is resettable, otherwise false.

Definition at line 718 of file qqmlproperty.cpp.

◆ isSignalProperty()

bool QQmlProperty::isSignalProperty ( ) const

Returns true if this QQmlProperty represents a QML signal property.

Definition at line 645 of file qqmlproperty.cpp.

◆ isValid()

bool QQmlProperty::isValid ( ) const

Returns true if the QQmlProperty refers to a valid property, otherwise false.

Definition at line 732 of file qqmlproperty.cpp.

◆ isWritable()

bool QQmlProperty::isWritable ( ) const

Returns true if the property is writable, otherwise false.

Definition at line 671 of file qqmlproperty.cpp.

◆ method()

QMetaMethod QQmlProperty::method ( ) const

Return the QMetaMethod for this property if it is a SignalProperty, otherwise returns an invalid QMetaMethod.

Definition at line 783 of file qqmlproperty.cpp.

◆ name()

QString QQmlProperty::name ( ) const

Return the name of this QML property.

Definition at line 742 of file qqmlproperty.cpp.

Referenced by testing.tools.encode_pdf_filter._PdfStream::RegisterByName().

+ Here is the caller graph for this function:

◆ needsNotifySignal()

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 1877 of file qqmlproperty.cpp.

◆ object()

QObject * QQmlProperty::object ( ) const

Returns the QQmlProperty's QObject.

Definition at line 653 of file qqmlproperty.cpp.

◆ operator=()

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

Assign other to this QQmlProperty.

Definition at line 661 of file qqmlproperty.cpp.

◆ operator==()

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

Returns true if other and this QQmlProperty represent the same property.

Definition at line 567 of file qqmlproperty.cpp.

◆ property()

QMetaProperty QQmlProperty::property ( ) const

Returns the \l{QMetaProperty} {Qt property} associated with this QML property.

Definition at line 769 of file qqmlproperty.cpp.

◆ propertyMetaType()

QMetaType QQmlProperty::propertyMetaType ( ) const

Returns the metatype of the property.

See also
propertyType

Definition at line 594 of file qqmlproperty.cpp.

◆ propertyType()

int QQmlProperty::propertyType ( ) const

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

See also
propertyMetaType

Definition at line 584 of file qqmlproperty.cpp.

◆ propertyTypeCategory()

QQmlProperty::PropertyTypeCategory QQmlProperty::propertyTypeCategory ( ) const

Returns the property category.

Definition at line 515 of file qqmlproperty.cpp.

◆ propertyTypeName()

const char * QQmlProperty::propertyTypeName ( ) const

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

Definition at line 548 of file qqmlproperty.cpp.

◆ read() [1/4]

QVariant QQmlProperty::read ( ) const

Returns the property value.

Definition at line 1067 of file qqmlproperty.cpp.

◆ read() [2/4]

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

Return the name property value of object.

This method is equivalent to:

QQmlProperty p(object, name);
p.read();
EGLImageKHR EGLint * name
GLfloat GLfloat p
[1]

Definition at line 1093 of file qqmlproperty.cpp.

◆ read() [3/4]

QVariant QQmlProperty::read ( const QObject * object,
const QString & name,
QQmlContext * ctxt )
static

Return the name property value of object using the \l{QQmlContext} {context} ctxt.

This method is equivalent to:

p.read();
static const QString context()
Definition java.cpp:394

Definition at line 1109 of file qqmlproperty.cpp.

◆ read() [4/4]

QVariant QQmlProperty::read ( const QObject * object,
const QString & name,
QQmlEngine * engine )
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:

p.read();
QJSEngine engine
[0]

Definition at line 1126 of file qqmlproperty.cpp.

◆ reset()

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 1836 of file qqmlproperty.cpp.

◆ swap()

void QQmlProperty::swap ( QQmlProperty & other)
inlinenoexcept

Definition at line 60 of file qqmlproperty.h.

◆ type()

QQmlProperty::Type QQmlProperty::type ( ) const

Returns the type of the property.

Definition at line 629 of file qqmlproperty.cpp.

◆ write() [1/4]

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 1768 of file qqmlproperty.cpp.

◆ write() [2/4]

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

Writes value to the name property of object.

This method is equivalent to:

QQmlProperty p(object, name);
p.write(value);
EGLOutputLayerEXT EGLint EGLAttrib value
[5]

Returns true on success, false otherwise.

Definition at line 1784 of file qqmlproperty.cpp.

◆ write() [3/4]

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

Writes value to the name property of object using the \l{QQmlContext} {context} ctxt.

This method is equivalent to:

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

Returns true on success, false otherwise.

Definition at line 1802 of file qqmlproperty.cpp.

◆ write() [4/4]

bool QQmlProperty::write ( QObject * object,
const QString & name,
const QVariant & value,
QQmlEngine * engine )
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:

p.write(value);

Returns true on success, false otherwise.

Definition at line 1824 of file qqmlproperty.cpp.

Friends And Related Symbol Documentation

◆ QQmlPropertyPrivate

friend class QQmlPropertyPrivate
friend

Definition at line 103 of file qqmlproperty.h.

Property Documentation

◆ name

QString QQmlProperty::name
read

◆ object

QML_ANONYMOUSQObject * QQmlProperty::object
read

Definition at line 27 of file qqmlproperty.h.


The documentation for this class was generated from the following files: