PDA

View Full Version : QStateMachine set state



matteo.ceruti
9th August 2012, 13:33
Hi,
I have a QStateMachine and I need to go directly at one QState without SIGNAL.
I need a function like GoToState(QAbstractState*).
Suggestions?
Thanks
Teo

33333
22nd October 2012, 07:33
Its pretty clear from the documentation that you can't (unfortunately? not sure), unless you extend QState yourself. Cant see why you would need to, except for convenience sake (agreed? not sure either :)). The way suggested is to put all states in a parent state and define a transition on the parent, then post an Event/Signal to the machine:



QStateMachine * m = new QStateMachine();
QState * operational = new QState(m);
QState * error = new QState(m);
QState * init = new QState(operational);
QState * a = new QState(operational);
QState * b = new QState(operational);
QState * c = new QState(operational);
//... more states ...
m->setInitialState(operational);
operational->setInitialState(init);

operational->addTransition(this,SIGNAL(error()),error);
error->addTranistion(this,SIGNAL(fixedError()),operationa l);
//... more transitions ...