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 编译器 .

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 必须指定。

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. 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 对话框。
  3. 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. 选择 OK to add the required import and to create the property for a non-singleton object.