我创建了一个 QStateMachine 并且我必须获取导致状态转换的事件。没有任何机会进入我的插槽EnterStateInit()
中导致此呼叫的信号。这是我的示例代码:
CreateStateMachine()
{
QState *Init = new QState();
QState *CheckPrecondition = new QState();
QState *DoWork = new QState();
Init->addTransition(this, SIGNAL(EventStart()), CheckPrecondition);
CheckPrecondition->addTransition(this, SIGNAL(EventSuccesfulCondition()), DoWork);
CheckPrecondition->addTransition(this, SIGNAL(EventNotSuccesfulCondition()), Init);
DoWork->addTransition(this, SIGNAL(EventWorkDone()), Init);
DoWork->addTransition(this, SIGNAL(EventError()), Init);
connect(Init, SIGNAL(entered()), this, SLOT(EnterStateInit()));
connect(CheckPrecondition, SIGNAL(entered()), this, SLOT(CheckPrecondition()));
connect(DoWork, SIGNAL(entered()), this, SLOT(DoWork()));
connect(Init, SIGNAL(exited()), this, SLOT(LeaveStateInit()));
connect(CheckPrecondition, SIGNAL(exited()), this, SLOT(LeaveStateCheckPrecondition()));
connect(DoWork, SIGNAL(exited()), this, SLOT(LeaveDoWork()));
mModuleStateMachine.addState(Init);
mModuleStateMachine.addState(CheckPrecondition);
mModuleStateMachine.addState(DoWork);
mModuleStateMachine.start();
}
EnterStateInit()
{
/* Get Event which caused this SLOT to react */
SetStatus();
}