Results 1 to 3 of 3

Thread: State Machine returning to previous state

  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 State Machine returning to previous state

    Hello,
    I've got a state machine, but I need a bit complexer behavior than the default: when I enter a particular state, some times I need to have a regular transition to another state. Other times I need to return to previous state.

    For example, having states A B C, say that transition T moves state from A to C and from B to C. I need that a transition S moves from C to A when T occurred in state A and from C to B when it occurred in state B.

    As you can see, this is a bit outside of the definition of finite state machine, as this is stack based and therefore needs "memory".

    I'm aware of the QHistoryState, but the documentation says it's made when moving outside the "level" of the current state (edit: precisely it says "A history state is a pseudo-state that represents the child state that the parent state was in the last time the parent state was exited"), while in my case, A, B and C are on the same level and as matter of facts it doesn't work

    Is there something in State Machine Framework that allows me to do this? Maybe subclassing QStateMachine or implementing a custom QAbstractState that may be similar to QHistoryState?

    I've some ideas on how to do this, but I'm hoping, of course, for an existing Qt solution.

    Thanks in advance
    ~Aki

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: State Machine returning to previous state

    My best guess would be to redesign your state machine so that A and B are substates of a new state X. Then C would become a kind of "external" state to your main state machine (formed from A, B and possibly some other states you might want to distinguish in future).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    akiross (10th May 2011)

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

    Default Re: State Machine returning to previous state

    Initially this wasn't an option, but I re-worked the state logic and managed to make it in that way to avoid writing custom classes.
    Thanks for the suggestion!

Similar Threads

  1. Replies: 0
    Last Post: 19th December 2010, 17:03
  2. State machine inside a QWidget
    By leoalvesmachado in forum Newbie
    Replies: 10
    Last Post: 4th August 2010, 19:36
  3. State machine implementation
    By yyiu002 in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2010, 05:57
  4. How to get this Qt state machine to work?
    By blukske in forum Qt Programming
    Replies: 0
    Last Post: 1st April 2010, 11:15
  5. Replies: 5
    Last Post: 9th May 2007, 22:31

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.