Reputation: 125
I have created a QStateMachine and I have to get the Event which has caused a transition of the state. Isn't there any opportunity to get inside my slot EnterStateInit()
the signal which caused this call. Here my sample code:
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();
}
Upvotes: 0
Views: 867
Reputation: 98425
A QState
is-a QObject
. You're free to reimplement its event()
method :) To get an idea of what's going on:
void MyState::event(QEvent * event) {
qDebug() << event;
QState::event(event);
}
Upvotes: 1