On this page

QObjectRegistryRef Class

This class is used to access an object registered with ObjectRegistry QML type from C++ code. More...

Header: #include <QObjectRegistryRef>
CMake: find_package(Qt6 REQUIRED COMPONENTS QmlDesignSupport)
target_link_libraries(mytarget PRIVATE Qt6::QmlDesignSupport)
qmake: QT += qmldesignsupport
Since: Qt 6.12
In QML: MultiObjectRegistryRef and ObjectRegistryRef
Inherits: QAbstractObjectRegistryRef

Properties

Public Functions

QObjectRegistryRef(QObject *parent = nullptr)
QObjectRegistryRef(QQmlEngine *engine, QObject *parent = nullptr)
QObjectRegistryRef(QQmlEngine *engine, const QString &key, QObject *parent = nullptr)
QObject *object() const

Signals

void objectChanged()

Detailed Description

Example usage:

// Register object in a QML file
MouseArea {
    ObjectRegistry.key: "MyMouseArea"
}

// In C++ code, refer to the registered object, using the QML engine you loaded the QML with
auto ref = new QObjectRegistryRef(engine, "MyMouseArea");
const auto object = ref->object();
connect(object, SIGNAL(clicked(QQuickMouseEvent*)),
        this, SLOT(myClickHandler()));

See also ObjectRegistry and QAbstractObjectRegistryRef::key.

Property Documentation

[read-only] object : QObject*

This property holds the object referenced by this instance.

If multiple objects are registered with the same key, the object referenced by this instance is an unspecified one of among them. Use QMultiObjectRegistryRef instead in that case.

Access functions:

QObject *object() const

Notifier signal:

void objectChanged()

See also ObjectRegistry and QAbstractObjectRegistryRef::key.

Member Function Documentation

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

Constructs QObjectRegistryRef instance with parent.

Note: Use this constructor only if the correct QML engine resolves automatically when the key is set. This generally does not happen when creating 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] QObjectRegistryRef::QObjectRegistryRef(QQmlEngine *engine, QObject *parent = nullptr)

Constructs QObjectRegistryRef instance with QML engine and parent. All registrations are scoped to the specified QML engine.

See also QAbstractObjectRegistryRef::key.

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

Constructs QObjectRegistryRef instance with QML engine, key and parent. All registrations are scoped to the specified QML engine.

See also QAbstractObjectRegistryRef::key.

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