4.6最新加入QStateMachine
今天在使用该类的时候,出现了一些从来没遇到过的问题,程序在执行a.exec()方法时挂掉了,觉得应该和该类的实现机制有关,所以决定首先对该类探个究竟。
QStateMachine类在corelib/statemachine中,继承自QState类,通过跟踪发现,最早的类是对QState类的一个抽象接口——QAbstractState类。整个QStateMachine的机制在Qt的The State Machine Framework文章中进行介绍。
在刚才无意间的操作中,发现最新的QtCreater已经可以完成对Qt源代码的编译,这样一来,以后再做分析和调试的时候,就更加方便了。
QStateMachine的设计应该来源于有限状态机的概念,主要提供对程序运行过程中不同状态间切换的管理工作。
Classes in the State Machine Framework
These classes are provided by qt for creating event-driven state machines.
The base class of states of a QStateMachine | |
The base class of transitions between QAbstractState objects | |
QObject-specific transition for Qt events | |
Final state | |
Means of returning to a previously active substate | |
Transition for key events | |
Transition for mouse events | |
Transition based on a Qt signal | |
General-purpose state for QStateMachine | |
Hierarchical finite state machine | |
Represents a Qt signal event | |
Holds a clone of an event associated with a QObject |
上面这些就是整个模块所包含的类了,我们现在对这些类间的继承关系进行分析。
上面的三个图,表示了该体系的整体继承关系。可以看出来,主要分为三部分,分别是负责存储状态的QAbstractState接口,负责对信号进行处理的QAbstractTransition接口,以及为状态机类提供信号事件的QEvent接口。
Let’s look at the detail description. We can see the QStateMachine class was designed by the thinking of finite state machine. Look,
The QStateMachine class provides a hierarchical finite state machine.
QStateMachine is based on the concepts and notation of Statecharts. QStateMachine is part of The State Machine Framework.