QQmlProperty Class
La clase QQmlProperty abstrae el acceso a las propiedades de los objetos creados a partir de QML. Más información...
| Encabezado: | #include <QQmlProperty> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
| qmake: | QT += qml |
| En QML: | qmlProperty |
Tipos públicos
| enum | PropertyTypeCategory { InvalidCategory, List, Object, Normal } |
| enum | Type { Invalid, Property, SignalProperty } |
Propiedades
Funciones públicas
| 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 |
Miembros públicos estáticos
| 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) |
Descripción detallada
Dado que QML utiliza el sistema de metatipos de Qt, todas las clases existentes de QMetaObject pueden utilizarse para analizar e interactuar con los objetos creados por QML. Sin embargo, algunas de las nuevas características que ofrece QML —como la seguridad de tipos y las propiedades asociadas— se utilizan más fácilmente a través de la clase QQmlProperty, que simplifica parte de su complejidad natural.
A diferencia de ` QMetaProperty `, que representa una propiedad de un tipo de clase, `QQmlProperty` encapsula una propiedad de una instancia de objeto específica. Para leer el valor de una propiedad, los programadores crean una instancia de `QQmlProperty` y llaman al método ` read()`. Del mismo modo, para escribir el valor de una propiedad se utiliza el método ` write()`.
Por ejemplo, para el siguiente código QML:
// MyItem.qml
import QtQuick 2.0
Text { text: "A bit of text" }Se podría acceder a las propiedades del objeto « Text » utilizando QQmlProperty, de la siguiente manera:
#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();Documentación sobre los tipos de miembros
enum QQmlProperty::PropertyTypeCategory
Esta enumeración especifica una categoría de propiedad QML.
| Constante | Valor | Descripción |
|---|---|---|
QQmlProperty::InvalidCategory | 0 | La propiedad no es válida o es una propiedad de señal. |
QQmlProperty::List | 1 | La propiedad es una propiedad de lista de tipo « QQmlListProperty » |
QQmlProperty::Object | 2 | La propiedad es un puntero de tipo derivado QObject |
QQmlProperty::Normal | 3 | La propiedad es una propiedad de valor normal. |
enum QQmlProperty::Type
Esta enumeración especifica un tipo de propiedad de QML.
| Constante | Valor | Descripción |
|---|---|---|
QQmlProperty::Invalid | 0 | La propiedad no es válida. |
QQmlProperty::Property | 1 | La propiedad es una propiedad Qt normal. |
QQmlProperty::SignalProperty | 2 | La propiedad es una propiedad de señal. |
Documentación de la propiedad
[read-only] name : const QString
Esta propiedad contiene el nombre de la propiedad QML.
Funciones de acceso:
| QString | name() const |
Véase también QQmlProperty::object.
[read-only] object : QObject* const
Esta propiedad contiene el objeto « QObject » representado por la propiedad de QML.
Funciones de acceso:
| QObject * | object() const |
Véase también QQmlProperty::name.
Documentación de las funciones de miembro
QQmlProperty::QQmlProperty()
Crea una propiedad QQmlProperty no válida.
QQmlProperty::QQmlProperty(QObject *obj)
Crea un objeto `QQmlProperty` para la propiedad por defecto de ` obj`. Si no existe ninguna propiedad por defecto, se creará un objeto `QQmlProperty` no válido.
QQmlProperty::QQmlProperty(QObject *obj, QQmlContext *ctxt)
Crea un objeto `QQmlProperty` para la propiedad por defecto de ` obj ` utilizando el método ` context ` ctxt. Si no existe ninguna propiedad por defecto, se creará un objeto `QQmlProperty` no válido.
QQmlProperty::QQmlProperty(QObject *obj, QQmlEngine *engine)
Crea un objeto `QQmlProperty` para la propiedad por defecto de ` obj `, utilizando el entorno para la instanciación de componentes QML que proporciona ` engine`. Si no existe ninguna propiedad por defecto, se creará un objeto `QQmlProperty` no válido.
QQmlProperty::QQmlProperty(QObject *obj, const QString &name)
Crea un objeto `QQmlProperty` para la propiedad « name » de ` obj`.
QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt)
Crea un objeto `QQmlProperty` para la propiedad ` name ` de ` obj ` utilizando ` context ` ctxt.
Si se crea un QQmlProperty sin un contexto, algunas propiedades —como las propiedades adjuntas— quedarán inaccesibles.
QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine)
Crea un objeto `QQmlProperty` para la propiedad ` name ` de ` obj `, utilizando el entorno para la instanciación de componentes QML que proporciona ` engine`.
QQmlProperty::QQmlProperty(const QQmlProperty &other)
Crea una copia de other.
bool QQmlProperty::connectNotifySignal(QObject *dest, const char *slot) const
Conecta la señal de notificación de cambios de la propiedad al slot especificado del objeto dest y devuelve «true». Devuelve «false» si esta metapropiedad no representa una propiedad Qt normal, si no tiene ninguna señal de notificación de cambios o si el objeto dest no tiene el slot especificado.
Nota: « slot » debe pasarse utilizando la macro SLOT() para que se identifique correctamente.
bool QQmlProperty::connectNotifySignal(QObject *dest, int method) const
Conecta la señal de notificación de cambios de la propiedad al « method » especificado del objeto « dest » y devuelve «true». Devuelve «false» si esta metapropiedad no representa una propiedad Qt habitual, si no tiene ninguna señal de notificación de cambios o si el objeto « dest » no tiene el « method » especificado.
bool QQmlProperty::hasNotifySignal() const
Devuelve «true» si la propiedad tiene una señal de notificación de cambios; en caso contrario, devuelve «false».
int QQmlProperty::index() const
Devuelve el índice del metaobjeto Qt de la propiedad.
bool QQmlProperty::isDesignable() const
Devuelve «true» si la propiedad es personalizable; en caso contrario, devuelve «false».
bool QQmlProperty::isProperty() const
Devuelve «true» si este objeto ` QQmlProperty ` representa una propiedad normal de Qt.
bool QQmlProperty::isResettable() const
Devuelve «true» si la propiedad se puede restablecer; en caso contrario, devuelve «false».
bool QQmlProperty::isSignalProperty() const
Devuelve «true» si este objeto ` QQmlProperty ` representa una propiedad de señal de QML.
bool QQmlProperty::isValid() const
Devuelve «true» si « QQmlProperty » hace referencia a una propiedad válida; en caso contrario, devuelve «false».
bool QQmlProperty::isWritable() const
Devuelve «true» si la propiedad es modificable; en caso contrario, devuelve «false».
QMetaMethod QQmlProperty::method() const
Devuelve el objeto ` QMetaMethod ` correspondiente a esta propiedad si se trata de un ` SignalProperty`; en caso contrario, devuelve un ` QMetaMethod` no válido.
QString QQmlProperty::name() const
Devuelve el nombre de esta propiedad QML.
Nota: Funcióngetter para la propiedad «name».
bool QQmlProperty::needsNotifySignal() const
Devuelve «true» si la propiedad necesita una señal de notificación de cambios para que los enlaces se mantengan actualizados; en caso contrario, devuelve «false».
Algunas propiedades, como las propiedades adjuntas o aquellas cuyo valor nunca cambia, no requieren un notificador de cambios.
QObject *QQmlProperty::object() const
Devuelve el objeto QObject del QQmlProperty.
Nota: Funcióngetter para el objeto de propiedad.
QMetaProperty QQmlProperty::property() const
Devuelve el objeto « Qt property » asociado a esta propiedad QML.
QMetaType QQmlProperty::propertyMetaType() const
Devuelve el metatipo de la propiedad.
Véase también propertyType.
int QQmlProperty::propertyType() const
Devuelve el identificador del metatipo de la propiedad, o « QMetaType::UnknownType » si la propiedad no tiene metatipo.
Véase también propertyMetaType.
QQmlProperty::PropertyTypeCategory QQmlProperty::propertyTypeCategory() const
Devuelve la categoría de la propiedad.
const char *QQmlProperty::propertyTypeName() const
Devuelve el nombre del tipo de la propiedad, o 0 si la propiedad no tiene nombre de tipo.
QVariant QQmlProperty::read() const
Devuelve el valor de la propiedad.
[static] QVariant QQmlProperty::read(const QObject *object, const QString &name)
Devuelve el valor de la propiedad « name » de « object ». Este método equivale a:
QQmlProperty p(object, name);
p.read();[static] QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlContext *ctxt)
Devuelve el valor de la propiedad « name » de « object » utilizando la función « context » ctxt. Este método es equivalente a:
QQmlProperty p(object, name, context);
p.read();[static] QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlEngine *engine)
Devuelve el valor de la propiedad « name » de « object » utilizando el entorno para la instanciación de componentes QML que proporciona engine. Este método es equivalente a:
QQmlProperty p(object, name, engine);
p.read();bool QQmlProperty::reset() const
Restablece la propiedad y devuelve «true» si la propiedad se puede restablecer. Si la propiedad no se puede restablecer, no ocurre nada y se devuelve «false».
QQmlProperty::Type QQmlProperty::type() const
Devuelve el tipo de la propiedad.
bool QQmlProperty::write(const QVariant &value) const
Establece el valor de la propiedad en « value ». Devuelve « true » si la operación se realiza correctamente, o « false » si no es posible establecer la propiedad, por ejemplo, porque el « value » es de un tipo incorrecto.
[static] bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value)
Escribe ` value ` en la propiedad ` name ` de ` object`. Este método es equivalente a:
QQmlProperty p(object, name);
p.write(value);Devuelve true si se realiza correctamente; en caso contrario, devuelve false.
[static] bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value, QQmlContext *ctxt)
Escribe « value » en la propiedad « name » de « object » utilizando el método « context » ctxt. Este método es equivalente a:
QQmlProperty p(object, name, ctxt);
p.write(value);Devuelve true si se realiza correctamente; en caso contrario, devuelve false.
[static] bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value, QQmlEngine *engine)
Escribe ` value ` en la propiedad ` name ` de ` object ` utilizando el entorno para instanciar componentes QML que proporciona ` engine`. Este método equivale a:
QQmlProperty p(object, name, engine);
p.write(value);Devuelve true si se realiza correctamente; en caso contrario, devuelve false.
QQmlProperty &QQmlProperty::operator=(const QQmlProperty &other)
Asigna other a este QQmlProperty.
bool QQmlProperty::operator==(const QQmlProperty &other) const
Devuelve «true» si other y este QQmlProperty representan la misma propiedad.
© 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.