[Solved] Qstatemachine transition
-
Could somebody please explain to me what i need to do.
i would like to know how to switch states whenever a certain function is called.i can switch states by using button clicks but i need my states to change automatically without any user input.
@ QStateMachine *machine = new QStateMachine(this);
State *listening = new State("listening"); State *identity = new State("identity"); State *relinquishing = new State("relinquishing"); State *exiting = new State("exiting"); QTimer *timer = new QTimer(relinquishing); timer->setInterval(5000); timer->setSingleShot(true); QObject::connect(this,SIGNAL(valueChanged(QString)),this,SLOT(settext(QString))); // default state - click on relinquish QObject::connect(listening,SIGNAL(entered()),this,SLOT(Relinquish())); // i wish to switch states here after i call the Relinquish() command. /* i'm stuck on this section */ // click on a button and switch states. //listening->addTransition(ui->reliniquish,SIGNAL(clicked()),relinquishing); // when exiting state switch to new state QObject::connect(listening,SIGNAL(exited()),this,SLOT(relinquish_text())); // relinquish state - click on exit button relinquishing->addTransition(ui->exit,SIGNAL(clicked()),listening); // start timer when entering state QObject::connect(relinquishing, SIGNAL(entered()),timer,SLOT(start())); // when timed out switch states relinquishing->addTransition(timer,SIGNAL(timeout()),identity); identity->addTransition(identity,SIGNAL(entered()),relinquishing); QObject::connect(identity,SIGNAL(entered()),this,SLOT(Identity())); // when exiting state switch to new state QObject::connect(relinquishing, SIGNAL(exited()),this,SLOT(listening_text())); machine->addState(listening); machine->addState(relinquishing); machine->addState(identity); machine->setInitialState(listening); machine->start();@
i found the answer on this page.
http://qt-project.org/doc/qt-5.0/qtcore/statemachine-api.html