Invoke Example (Static)
演示如何使用
<invoke>
element with generated nested state-machines, where the SCXML file is compiled to a C++ class. The
<invoke>
element is used to create an instance of an external service.
要运行范例从 Qt Creator ,打开 欢迎 模式,然后选择范例从 范例 。更多信息,拜访 构建和运行范例 .
在 statemachine.scxml , we specify a state machine with the name 方向 类型 http://www.w3.org/TR/scxml/ to invoke:
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="Directions" initial="anyplace" > <state id="anyplace"> <transition event="goNowhere" target="nowhere"/> <transition event="goSomewhere" target="somewhere"/> <state id="nowhere"/> <state id="somewhere"> <invoke type="http://www.w3.org/TR/scxml/"> <content> <scxml name="anywhere" version="1.0"> <state id="here"> <transition event="goThere" target="there"/> </state> <state id="there"> <transition event="goHere" target="here"/> </state> </scxml> </content> </invoke> </state> </state> </scxml>
We link against the Qt SCXML module by adding the following line to the invoke-static.pro 文件:
QT += qml scxml
接着,指定要编译的状态机:
STATECHARTS = ../invoke-common/statemachine.scxml
Qt SCXML 编译器
qscxmlc
, is run automatically to generate
statemachine.h
and
statemachine.cpp
, and to add them to the
HEADERS
and
SOURCES
variables for compilation.
We instantiate the generated
方向
类在
invoke-static.cpp
文件,如下:
#include "statemachine.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qmlRegisterType<Directions>("Directions", 1, 0, "Directions"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/invoke-static.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
文件: