Unsolved how to override QState and use it
-
@AndreAhmed
well a given state is active when no Transition has happened.do you mean like a function being called over and over while in a state?
-
yes I mean a function that's called over and over , then after a condition like if(cnt==5) go to next state.
-
a giving state is active but it only calls onEnter() just once.
-
@AndreAhmed
Hi
Look here
https://doc.qt.io/archives/4.6/statemachine-trafficlight.htmlThey use a timer.
You could do the same and simply enable onEnter
and turn off onExit. -
hi,
thanks for the answer. How would I put a timer for onEntry() I'm so confused
-
@AndreAhmed
Add a QTimer timer; to your state
add a slot to your state
connect timer to slotOnEnter
timer.start(1000); // call ur slot every 1 secOnExit
timer.stop(); -
Can I say addtransition inside the slot of the timer so that to move to another state ?
how to manage states then, they should be in one cpp file ?
-
@AndreAhmed
You can use any normal QState function in the slot to advance state.Well, I guess keeping related states in same cpp sounds like good plan.
You did see
http://doc.qt.io/qt-5/statemachine-api.html
? -
Yes I did but didn't know how to use the classes of the QState,..etc.
So the steps now
- Inherit from QState and implement onEnter on Exit
- make a timer
- start the timer in onEnter()
- do the logic inside the slot of the timer
- add the transition there
-
hi
Yes something like that. Please make Timer a class member.Just a note:
Well it has signals also
void entered()
void exited()
http://doc.qt.io/qt-5/qabstractstate.html#entered
So you dont need to subclass to use Enter/exit.