In questa pagina

QQmlProperty Class

La classe QQmlProperty astrae l'accesso alle proprietà degli oggetti creati da QML. Per saperne di più...

Intestazione: #include <QQmlProperty>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
In QML: qmlProperty

Tipi pubblici

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

Proprietà

Funzioni pubbliche

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
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
QQmlProperty &operator=(const QQmlProperty &other)
bool operator==(const QQmlProperty &other) const

Membri pubblici statici

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)

Descrizione dettagliata

Poiché QML utilizza il sistema di metatipi di Qt, tutte le classi esistenti di QMetaObject possono essere utilizzate per l'introspezione e l'interazione con gli oggetti creati da QML. Tuttavia, alcune delle nuove funzionalità fornite da QML — come la sicurezza dei tipi e le proprietà associate — sono più facilmente utilizzabili tramite la classe QQmlProperty, che ne semplifica parte della naturale complessità.

A differenza di ` QMetaProperty `, che rappresenta una proprietà su un tipo di classe, `QQmlProperty` incapsula una proprietà su una specifica istanza di oggetto. Per leggere il valore di una proprietà, i programmatori creano un'istanza di `QQmlProperty` e chiamano il metodo ` read()`. Allo stesso modo, per scrivere il valore di una proprietà si utilizza il metodo ` write()`.

Ad esempio, per il seguente codice QML:

// MyItem.qml
import QtQuick 2.0

Text { text: "A bit of text" }

È possibile accedere alle proprietà dell’oggetto ` Text ` utilizzando `QQmlProperty`, in questo modo:

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

Documentazione sui tipi di iscrizione

enum QQmlProperty::PropertyTypeCategory

Questa enumerazione specifica una categoria di proprietà QML.

CostanteValoreDescrizione
QQmlProperty::InvalidCategory0La proprietà non è valida oppure è una proprietà di segnale.
QQmlProperty::List1La proprietà è una proprietà di tipo elenco " QQmlListProperty "
QQmlProperty::Object2La proprietà è un puntatore a un tipo derivato di QObject
QQmlProperty::Normal3La proprietà è una proprietà di valore normale.

enum QQmlProperty::Type

Questa enumerazione specifica un tipo di proprietà QML.

CostanteValoreDescrizione
QQmlProperty::Invalid0La proprietà non è valida.
QQmlProperty::Property1La proprietà è una normale proprietà Qt.
QQmlProperty::SignalProperty2La proprietà è una proprietà di segnale.

Documentazione della proprietà

[read-only] name : const QString

Questa proprietà contiene il nome della proprietà QML.

Funzioni di accesso:

QString name() const

Vedi anche QQmlProperty::object.

[read-only] object : QObject* const

Questa proprietà contiene l'QObject e rappresentata dalla proprietà QML.

Funzioni di accesso:

QObject *object() const

Vedi anche QQmlProperty::name.

Documentazione delle funzioni membro

QQmlProperty::QQmlProperty()

Crea una proprietà QQmlProperty non valida.

QQmlProperty::QQmlProperty(QObject *obj)

Crea una QQmlProperty per la proprietà predefinita di obj. Se non esiste una proprietà predefinita, verrà creata una QQmlProperty non valida.

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

Crea un oggetto `QQmlProperty` per la proprietà predefinita di ` obj ` utilizzando l'context e ctxt. Se non esiste una proprietà predefinita, verrà creato un oggetto `QQmlProperty` non valido.

QQmlProperty::QQmlProperty(QObject *obj, QQmlEngine *engine)

Crea un oggetto `QQmlProperty` per la proprietà predefinita di ` obj `, utilizzando l'ambiente per l'istanziazione dei componenti QML fornito da ` engine`. Se non è presente alcuna proprietà predefinita, verrà creato un oggetto `QQmlProperty` non valido.

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

Crea un oggetto QQmlProperty per la proprietà “ name ” di obj.

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

Crea una QQmlProperty per la proprietà name di obj utilizzando l'context ctxt .

La creazione di un oggetto QQmlProperty senza un contesto renderà alcune proprietà — come le proprietà associate — inaccessibili.

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

Crea una QQmlProperty per la proprietà name di obj utilizzando l'ambiente per l'istanziazione dei componenti QML fornito da engine.

QQmlProperty::QQmlProperty(const QQmlProperty &other)

Crea una copia di other.

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

Collega il segnale di notifica delle modifiche della proprietà all’ slot specificato dell’oggetto dest e restituisce true. Restituisce false se questa metaproprietà non rappresenta una proprietà Qt regolare, se non dispone di un segnale di notifica delle modifiche oppure se l’oggetto dest non possiede l’ slot specificato.

Nota: ` slot ` deve essere passato utilizzando la macro `SLOT()` affinché venga identificato correttamente.

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

Collega il segnale di notifica delle modifiche della proprietà all'method e specificato dell'oggetto dest e restituisce true. Restituisce false se questa metaproprietà non rappresenta una normale proprietà Qt, se non dispone di un segnale di notifica delle modifiche oppure se l'oggetto dest non possiede l'method specificato.

bool QQmlProperty::hasNotifySignal() const

Restituisce "true" se la proprietà dispone di un segnale di notifica delle modifiche, altrimenti "false".

int QQmlProperty::index() const

Restituisce l'indice del metaoggetto Qt della proprietà.

bool QQmlProperty::isDesignable() const

Restituisce “true” se la proprietà è personalizzabile, altrimenti “false”.

bool QQmlProperty::isProperty() const

Restituisce true se questo oggetto ` QQmlProperty ` rappresenta una proprietà Qt standard.

bool QQmlProperty::isResettable() const

Restituisce true se la proprietà è reimpostabile, altrimenti false.

bool QQmlProperty::isSignalProperty() const

Restituisce `true` se questo QQmlProperty rappresenta una proprietà di segnale QML.

bool QQmlProperty::isValid() const

Restituisce true se l'QQmlProperty e fa riferimento a una proprietà valida, altrimenti false.

bool QQmlProperty::isWritable() const

Restituisce true se la proprietà è scrivibile, altrimenti false.

QMetaMethod QQmlProperty::method() const

Restituisce l'oggetto ` QMetaMethod ` per questa proprietà se si tratta di un ` SignalProperty`; in caso contrario, restituisce un ` QMetaMethod` non valido.

QString QQmlProperty::name() const

Restituisce il nome di questa proprietà QML.

Nota: funzionegetter per il nome della proprietà.

bool QQmlProperty::needsNotifySignal() const

Restituisce true se la proprietà richiede un segnale di notifica delle modifiche affinché i binding rimangano aggiornati; in caso contrario, restituisce false.

Alcune proprietà, come quelle associate o quelle il cui valore non cambia mai, non richiedono un notificatore di modifica.

QObject *QQmlProperty::object() const

Restituisce il metodo ` QObject` dell'QQmlProperty.

Nota: Funzionegetter per l'oggetto della proprietà.

QMetaProperty QQmlProperty::property() const

Restituisce l’ Qt property associato a questa proprietà QML.

QMetaType QQmlProperty::propertyMetaType() const

Restituisce il metatipo della proprietà.

Vedi anche propertyType.

int QQmlProperty::propertyType() const

Restituisce l'ID del metatipo della proprietà oppure QMetaType::UnknownType se la proprietà non ha alcun metatipo.

Vedi anche propertyMetaType.

QQmlProperty::PropertyTypeCategory QQmlProperty::propertyTypeCategory() const

Restituisce la categoria della proprietà.

const char *QQmlProperty::propertyTypeName() const

Restituisce il nome del tipo della proprietà oppure 0 se la proprietà non ha un nome di tipo.

QVariant QQmlProperty::read() const

Restituisce il valore della proprietà.

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

Restituisce il valore della proprietà ` name ` di ` object`. Questo metodo è equivalente a:

QQmlProperty p(object, name);
p.read();

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

Restituisce il valore della proprietà ` name ` di ` object ` utilizzando ` context ` ctxt. Questo metodo è equivalente a:

QQmlProperty p(object, name, context);
p.read();

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

Restituisce il valore della proprietà ` name ` di ` object ` utilizzando l'ambiente per l'istanziazione dei componenti QML fornito da engine. . Questo metodo è equivalente a:

QQmlProperty p(object, name, engine);
p.read();

bool QQmlProperty::reset() const

Reimposta la proprietà e restituisce true se la proprietà è reimpostabile. Se la proprietà non è reimpostabile, non accade nulla e viene restituito false.

QQmlProperty::Type QQmlProperty::type() const

Restituisce il tipo della proprietà.

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

Imposta il valore della proprietà su value. Restituisce true in caso di esito positivo, oppure false se non è possibile impostare la proprietà, ad esempio perché il tipo di value non è corretto.

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

Scrive ` value ` nella proprietà ` name ` di ` object`. Questo metodo è equivalente a:

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

Restituisce true in caso di esito positivo, false in caso contrario.

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

Scrive value nella proprietà name di object utilizzando il metodo context ctxt . Questo metodo è equivalente a:

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

Restituisce true in caso di esito positivo, false in caso contrario.

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

Scrive value nella proprietà name di object utilizzando l'ambiente per l'istanziazione dei componenti QML fornito da engine. Questo metodo è equivalente a:

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

Restituisce true in caso di esito positivo, false in caso contrario.

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

Assegna other a questo QQmlProperty.

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

Restituisce true se other e questo QQmlProperty rappresentano la stessa proprietà.

© 2026 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 the GNU 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.