Managing C++ Backend Objects

Many applications provide QObject objects implemented in C++ that work as a bridge between QML and C++. Such objects are typically registered with qmlRegisterType or qmlRegisterSingletonType and then used by QML to communicate with the C++ backend. Another example of such objects are the state machines created by the Qt SCXML Compiler.

Backend objects in a QML file are accessible if the QML file contains the required imports. In addition, for a non-singleton QObject, a dynamic property that contains the QObject must be specified.

A local QObject is instantiated in the current .qml file, as follows:

property MyType myType: MyType {}.

Otherwise the property is just defined, as follows:

property MyType myType

To manage backend objects:

  1. In the Connections view, select the Backends tab to view accessible backend objects.

  2. Select the (Add) button to add a backend object in the Add New C++ Backend dialog.
  3. In the Type field, select the type of the backend QObject to add.
  4. Select the Define object locally check box if the QObject is not registered as a singleton.
  5. Select OK to add the required import and to create the property for a non-singleton object.

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