ObjectRegistry QML Type

This type is used to register objects for later access based on a key string. More...

Import Statement: import QtQml.DesignSupport
Since: Qt 6.12

Properties

Detailed Description

The object registry provides a QML engine-wide reference for objects. You register each object with a string key, which you can use later to retrieve the object through one of the following reference types: ObjectRegistryRef and MultiObjectRegistryRef. C++ classes are also provided for accessing registered objects: QObjectRegistryRef and QMultiObjectRegistryRef.

The same key can be used to register multiple objects. A typical use case for this is registering a list or repeater delegate.

The registered object is automatically removed from the registry on either object destruction or ObjectRegistry instance destruction. Changing the target object or the key removes the old combination from the registry.

Do not register the same object and key combination more than once. Only one registration per combination is stored.

The registration can be done either with attached property on the registered object or using separate ObjectRegistry object with target and key:

 // Registering with attached property
 Item {
     id: itemToRegister
     ObjectRegistry.key: "MyItem"
 }

 // Registering with separate ObjectRegistry object
 Item {
     id: itemToRegister
     ObjectRegistry {
         target: itemToRegister
         key: "MyItem"
     }
 }

See also ObjectRegistryRef, MultiObjectRegistryRef, QObjectRegistryRef, and QMultiObjectRegistryRef.

Property Documentation

key : string

This property specifies the key of the registered object.

target : QtObject

This property specifies the target object to register.