The Qt SCXML module provides classes for embedding state machines created from State Chart XML (SCXML) files in Qt applications. The SCXML files can be created using any suitable tool, such as a text editor or a simulator, as long as they comply to the SCXML Specification , with the restrictions and extensions described in SCXML Compliance .
Parts of the application logic can be replaced with an encapsulated SCXML file. This enables creating a clear division between the application logic and the user interface implementation by using Qt Quick or Qt Widgets.
The Qt SCXML module differs from the 状态机框架 in the Qt Core module in that Qt SCXML provides a conforming processor that can parse and process conforming SCXML documents . In Qt SCXML, state machines are read from separate SCXML files and integrated to Qt applications by instantiating the QScxmlStateMachine class and loading an SCXML file dynamically or by using the Qt SCXML Compiler to generate a subclass of QScxmlStateMachine that is instantiated. The communication with the SCXML document is provided by the signals and methods of the QScxmlStateMachine 类。
The basic state machine concepts, state , transition ，和 event are based on those in the SCXML Specification. State charts provide a graphical way of modeling how a system reacts to stimuli. This is done by defining the possible states that the system can be in, and how the system can move from one state to another (transitions between states). A key characteristic of event-driven systems (such as Qt applications) is that behavior often depends not only on the last or current event, but also the events that preceded it. With state charts, this information is easy to express.
Qt SCXML integrates tightly with Qt's meta-object system; for example, transitions between states can be triggered by signals, and states can be configured to set properties and invoke methods on QObjects . Qt's event system is used to drive the state machines.
The state graph in Qt SCXML is hierarchical. States can be nested inside other states, and the current configuration of the state machine consists of the set of states that are currently active.
Qt SCXML supports the null data model, which must be supported by conforming SCXML processors, and the ECMAScript data model. In addition, Qt SCXML provices its own C++ data model that is implemented by the
class. The class enables writing C++ code for
of the data model is backed by a subclass of
, for which the Qt SCXML compiler will generate the dispatch methods.
The Qt SCXML Compiler,
, reads an .scxml file and produces C++ source and header files that contain a class that implements a state machine as defined in SCXML. For more information about using the compiler, see
使用 Qt SCXML 编译器 (qscxmlc)
Both the dynamically created and the compiled state machines behave in the same way, have the same properties, states, data model, and so on. They only differ in the way they are instantiated. For more information, see 实例化状态机 and Qt SCXML 范例 .
The Qt SCXML module exports the following logging categories:
|qscxmlLog||Enables Qt SCXML module log|
|scxmlLog||Enables log of SCXML documents|