Qt State Machine 概述

The State Machine framework provides classes for creating and executing state graphs. The concepts and notation are based on those from Harel's Statecharts: A visual formalism for complex systems , which is also the basis of UML state diagrams. The semantics of state machine execution are based on SCXML (状态图表 XML) .

Statecharts provide a graphical way of modeling how a system reacts to stimuli. This is done by defining the possible 状态 that the system can be in, and how the system can move from one state to another ( 过渡 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 statecharts, this information is easy to express.

The State Machine framework provides an API and execution model that can be used to effectively embed the elements and semantics of statecharts in Qt applications. The framework 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 { QObject }s. Qt's event system is used to drive the state machines.

The state graph in the State Machine framework is hierarchical. States can be nested inside of other states, and the current configuration of the state machine consists of the set of states which are currently active. All the states in a valid configuration of the state machine will have a common ancestor.

另请参阅 Qt State Machine C++ 指南 , Qt State Machine QML 指南 ,和 Qt SCXML 概述 .