QMultiObjectRegistryRef Class
This class is used to access objects registered with ObjectRegistry QML type from C++ code. More...
| Header: | #include <QMultiObjectRegistryRef> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS QmlDesignSupport)target_link_libraries(mytarget PRIVATE Qt6::QmlDesignSupport) |
| qmake: | QT += qmldesignsupport |
| Since: | Qt 6.12 |
| Inherits: | QAbstractObjectRegistryRef |
- List of all members, including inherited members
- QMultiObjectRegistryRef is part of Qt Qml Design Support C++ Classes.
Properties
- objects : QQmlListProperty<QObject>
Public Functions
| 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() |
Signals
| void | objectAdded(QObject *obj) |
| void | objectRemoved(QObject *obj) |
| void | objectsChanged() |
Detailed Description
Multiple objects registered with the same key can be accessed via this reference.
Example usage:
// In a QML file, register something that gets created multiple times (e.g. a repeater delegate)
Repeater {
model: 4
Rectangle {
id: qmlRepeaterDelegate
required property int index
x: 50 * index
width: 40
height: 40
MouseArea {
property int repeaterIndex: qmlRepeaterDelegate.index
anchors.fill: parent
ObjectRegistry.key: "RepeatedMouseArea"
}
}
}
// In C++ code, refer to the registered objects, using the QML engine you loaded the QML with
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()
}See also ObjectRegistry and QAbstractObjectRegistryRef::key.
Property Documentation
[read-only] objects : QQmlListProperty<QObject>
This property provides the objects referenced by this instance. The order of the objects in this list is not guaranteed to match the order of their registration.
Access functions:
| QQmlListProperty<QObject> | objects() |
Notifier signal:
| void | objectsChanged() |
See also objectsList(), ObjectRegistry, and AbstractObjectRegistryRef::key.
Member Function Documentation
[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QObject *parent = nullptr)
Constructs QMultiObjectRegistryRef instance with parent.
Note: Use this constructor only if the correct QML engine resolves automatically for this instance when the key is set. This is typically not the case when constructing an instance of this class from C++. It is recommended to use one of the constructors that take a QML engine pointer as a parameter.
See also qmlEngine() and QAbstractObjectRegistryRef::key.
[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QQmlEngine *engine, QObject *parent = nullptr)
Constructs QMultiObjectRegistryRef instance with QML engine and parent. All registrations are scoped to the specified QML engine.
See also QAbstractObjectRegistryRef::key.
[explicit] QMultiObjectRegistryRef::QMultiObjectRegistryRef(QQmlEngine *engine, const QString &key, QObject *parent = nullptr)
Constructs QMultiObjectRegistryRef instance with QML engine, key and parent. All registrations are scoped to the specified QML engine.
See also QAbstractObjectRegistryRef::key.
[signal] void QMultiObjectRegistryRef::objectAdded(QObject *obj)
This signal is emitted when a new object, obj, has been registered with the key of this reference.
[signal] void QMultiObjectRegistryRef::objectRemoved(QObject *obj)
This signal is emitted when an object, obj, registration has been removed with the key of this reference.
QList<QObject *> QMultiObjectRegistryRef::objectsList()
Returns the list of registered objects matching the key of this instance.
This is a method to get the list of registered objects as a QList.
The order of the objects in this list is not guaranteed to match the order of their registration.
See also QAbstractObjectRegistryRef::key and 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.