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:
(
Add
) button to add a backend object in the
Add New C++ Backend
对话框。