En esta página

QMultiObjectRegistryRef Class

Esta clase se utiliza para acceder desde código C++ a objetos registrados con el tipo QML « ObjectRegistry ». Más información...

Cabecera: #include <QMultiObjectRegistryRef>
CMake: find_package(Qt6 REQUIRED COMPONENTS QmlDesignSupport)
target_link_libraries(mytarget PRIVATE Qt6::QmlDesignSupport)
qmake: QT += qmldesignsupport
Desde: Qt 6.12
Heredado de: QAbstractObjectRegistryRef

Propiedades

  • objects : QQmlListProperty<QObject>

Funciones públicas

QMultiObjectRegistryRef(QObject *parent = nullptr)
QMultiObjectRegistryRef(QQmlEngine *engine, QObject *parent = nullptr)
QMultiObjectRegistryRef(QQmlEngine *engine, const QString &key, QObject *parent = nullptr)
QQmlListProperty<QObject> objects()
QList<QObject *> objectsList()

Señales

void objectAdded(QObject *obj)
void objectRemoved(QObject *obj)
void objectsChanged()

Funciones protegidas reimplementadas

virtual bool event(QEvent *event) override

Descripción detallada

A través de esta referencia se puede acceder a varios objetos registrados con la misma clave.

Ejemplo de uso:

// En un archivo QML, registra algo que se crea varias veces (por ejemplo, un delegado de repetidor)
Repeater {
    model: 4
    Rectangle {
        id: qmlRepeaterDelegate
        propiedad requerida int index
        x: 50 * index
        width: 40
        height: 40
        MouseArea {
            propiedad int repeaterIndex: qmlRepeaterDelegate.index
            anchors.fill: parent
            ObjectRegistry.key: "RepeatedMouseArea"
        }
    }
}

// En el código C++, haz referencia a los objetos registrados utilizando el motor QML con el que has cargado el archivo QML
auto ref = new QMultiObjectRegistryRef(engine, "RepeatedMouseArea");
const auto repeaterObjects = ref->objects();
for (auto obj : repeaterObjects) {
    connect(obj, SIGNAL(clicked(QQuickMouseEvent*)),
            this, SLOT(handleRepeaterObjectClicked()));
}

void MyClass::handleRepeaterObjectClicked()
{
    qDebug() << "Clicked rectangle index: " << sender()->property("repeaterIndex").toInt()
}

Véase también ObjectRegistry y QAbstractObjectRegistryRef::key.

Documentación de propiedades

[read-only] objects : QQmlListProperty<QObject>

Esta propiedad proporciona los objetos a los que hace referencia esta instancia. No se garantiza que el orden de los objetos en esta lista coincida con el orden en que se registraron.

Funciones de acceso:

QQmlListProperty<QObject> objects()

Señal de notificador:

void objectsChanged()

Véase también objectsList(), ObjectRegistry y AbstractObjectRegistryRef::key.

Documentación de funciones de miembro

[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QObject *parent = nullptr)

Crea una instancia de `QMultiObjectRegistryRef` con ` parent`.

Nota: Utiliza este constructor solo si el motor QML correcto se resuelve automáticamente para esta instancia cuando se establece la clave. Normalmente, este no es el caso cuando se crea una instancia de esta clase desde C++. Se recomienda utilizar uno de los constructores que toman un puntero al motor QML como parámetro.

Véase también ` qmlEngine()` y ` QAbstractObjectRegistryRef::key`.

[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QQmlEngine *engine, QObject *parent = nullptr)

Crea una instancia de `QMultiObjectRegistryRef` con los registros de `QML` engine y parent. Todos los registros tienen como ámbito el motor de QML especificado.

Véase también QAbstractObjectRegistryRef::key.

[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QQmlEngine *engine, const QString &key, QObject *parent = nullptr)

Crea una instancia de `QMultiObjectRegistryRef` con los elementos QML ` engine`, ` key ` y ` parent`. Todos los registros tienen como ámbito el motor QML especificado.

Véase también QAbstractObjectRegistryRef::key.

[override virtual protected] bool QMultiObjectRegistryRef::event(QEvent *event)

Reimplementa: ` QAbstractObjectRegistryRef::event(QEvent *event)`.

[signal] void QMultiObjectRegistryRef::objectAdded(QObject *obj)

Esta señal se emite cuando se ha registrado un nuevo objeto, obj, con la clave de esta referencia.

[signal] void QMultiObjectRegistryRef::objectRemoved(QObject *obj)

Esta señal se emite cuando se ha eliminado el registro de un objeto, obj, utilizando la clave de esta referencia.

QList<QObject *> QMultiObjectRegistryRef::objectsList()

Devuelve la lista de objetos registrados que coinciden con la clave de esta instancia.

Este es un método para obtener la lista de objetos registrados como un objeto de tipo ` QList`.

No se garantiza que el orden de los objetos en esta lista coincida con el orden en que se registraron.

Véase también « QAbstractObjectRegistryRef::key » y « objects ».

© 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.