使用 Qt SCXML 编译器 (qscxmlc)

The qscxmlc tool reads an .scxml file and produces C++ source and header files, containing a class that implements a state machine as defined in SCXML.

用法

The qscxml tool is invoked automatically if the QT variable in the project file includes scxml , and the .scxml file to use is specified using the STATECHARTS 变量。

QT += scxml
STATECHARTS = MyStatemachine.scxml
					

With above definitions, qmake invokes qscxmlc to generate MyStatemachine.h and MyStatemachine.cpp, and adds them to HEADERS and SOURCES 变量。

By default, the name of the generated class that implements the state machine corresponds with the name 属性在 <scxml> 根元素。

命令行选项

The qscxmlc tool supports the following command-line options, which can be specified using the QSCXMLC_ARGUMENTS variable in the project file:

选项 描述
--namespace <namespace> Put the generated class(es) in the specified namespace. You can use the QSCXMLC_NAMESPACE variable to specify this in your project file.
-o <base/out/name> The base name of the output files. This can include a path. If none is specified, the basename of the input file is used.
--header <header/out> The name of the output header file. If none is specified, .h is added to the base name.
--impl <cpp/out> The name of the output header file. If none is specified, .cpp is added to the base name.
--classname <StateMachineClassName> The class name of the generated state machine. If none is specified, the value of the name attribute of the <scxml> tag is taken. If that attribute is not specified either, the basename (excluding path) is taken from the input file name.
--statemethods Generate extra accessor and signal methods for states. This way you can connect to state changes with plain QObject::connect () and directly call a method to find out if a state is currently active.