Results 1 to 2 of 2

Thread: QState entered and exited automatically. Strange behavior?

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QState entered and exited automatically. Strange behavior?

    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

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QState entered and exited automatically. Strange behavior?

    Quote Originally Posted by akiross View Post
    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.

    Quote Originally Posted by akiross View Post
    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.
    Last edited by franz; 3rd May 2011 at 06:19.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. setCellWidget - strange behavior
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 28th April 2011, 08:26
  2. Replies: 4
    Last Post: 25th March 2010, 10:32
  3. Qt Creator Strange behavior of GDB in Creator 1.3
    By rayjc in forum Qt Tools
    Replies: 1
    Last Post: 11th March 2010, 21:42
  4. QComboBox strange behavior
    By Antebios in forum Newbie
    Replies: 2
    Last Post: 31st March 2009, 23:50
  5. scrollbars strange behavior
    By siniy in forum Qt Programming
    Replies: 6
    Last Post: 29th December 2006, 10:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.