PDA

View Full Version : QState entered and exited automatically. Strange behavior?



akiross
3rd May 2011, 00:16
Hello,
I've a question about a behavior of QState which I find "weird", I'm trying to understand why it behaves in this way.

I created a state machine with 2 states: Ready and Searching. Ready is the initial state.
Searching is parent state: it contains an Empty QState, a NonEmpty QState and a Final QFinalState.
Empty is the initial state in Searching state. The state switches to NonEmpty if a certain guard is met, when some event occur.

The automata has been set up like this:
when a special key is pressed, state passes from Ready to Searching with a QKeyEventTransition.
Empty starts as initial state, then we can have (or not have) a transition to NonEmpty, depending on user input and system state. I need that when in Searching state (and thus in Empty or NonEmpty state), if user presses Escape, the computation is stopped and the state returns to Ready.

When user presses Escape, the state goes from Empty or NonEmpty to Final. Then a QSignalTransition is used to capture the finished() signal and change the state to Ready.

The problem is: doing things this way, when user presses Escape, Searching is exited, then entered, then again exited. If I don't catch the finished() signal, the machine will loop forever entering and exiting the Searching state (sic!).

Instead, if I don't use the Final state, but create a transition directly from Searching to Ready, it works as expected and Searching is exited as expected.

I double and triple-checked the code, it's a bit complex and I prefer not to post it - hoping my explanation is clear.

Does someone of you have a clue about why this happens?
If needed (i.e. not obvious solution) I can try to post the code.

Thanks in advance
~Aki

franz
3rd May 2011, 06:19
I double and triple-checked the code, it's a bit complex and I prefer not to post it - hoping my explanation is clear.

Does someone of you have a clue about why this happens?
If needed (i.e. not obvious solution) I can try to post the code.

With these types of bugs it is often the case that the description of the code does not match the actual code. If you are apprehensive of posting all your code, copy/paste the relevant parts of your state machine setup, particularly all the transition setup calls.


I double and triple-checked the code, it's a bit complex and I prefer not to post it - hoping my explanation is clear.

Does someone of you have a clue about why this happens?
If needed (i.e. not obvious solution) I can try to post the code.

With these types of bugs it is often the case that the description of the code does not match the actual code. If you are apprehensive of posting all your code, copy/paste the relevant parts of your state machine setup, particularly all the transition setup calls.

Added after 8 minutes:

On rereading your post though, I think that your Searching state is stuck in QFinalState (obvious, no?) and is always emitting the finished() signal or something like that. Since you state that dropping the final state suits your purpose, you should go for that, or make sure that the correct sub-state is entered when you enter searching state.