Invokes a compiled nested state machine.
Invoke Example (Static) demonstrates how to use the <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.
To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.
In statemachine.scxml, we specify a state machine with the name Directions of type 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 lines to the example's build files.
QT += qml scxml
We then specify the state machine to compile:
STATECHARTS = ../invoke-common/statemachine.scxml
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) target_link_libraries(invoke-static PUBLIC Qt6::Core Qt6::Gui Qt6::Qml Qt6::Scxml )
We then specify the state machine to compile:
qt6_add_statecharts(invoke-static ../invoke-common/statemachine.scxml )
The statechart directives STATECHARTS or qt6_add_statecharts invoke the Qt SCXML Compiler, qscxmlc
, which is run automatically to generate statemachine.h and statemachine.cpp, which
are then added appropriately as headers and sources for compilation.
We instantiate the generated Directions
class in the invoke-static.cpp file, as follows:
#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(); }
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: