Results 1 to 6 of 6

Thread: qstatemachine how to do conditional transitions based on concurrent state

  1. #1
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    1

    Default qstatemachine how to do conditional transitions based on concurrent state

    in D. Harel's 1987 paper, in figures 19 & 20, he describes a notational method for making state transitions in AND-parallel states where the transition (fig-19: beta(G)) is conditioned on the state of the adjacent sub-state-machine. Is there a best practices recommendation for implementing this same functionality with qstatemachine? There does not seem to be a direct method for this.

    thanks

  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: qstatemachine how to do conditional transitions based on concurrent state

    When referring to an article it would be polite to at least give the title of the article and any means of finding it.
    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. #3
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    1

    Default Re: qstatemachine how to do conditional transitions based on concurrent state

    My Apologies. it was bad of me to assume that only those already familiar with the paper ( i.e the authors of QStateMachines) would be responding.

    its an old paper so only available in scanned-pdf:

    The Qt statemachine frame work page contains a link to the paper:

    http://www.wisdom.weizmann.ac.il/~ha...tatecharts.pdf

    Statecharts: A Visual Formalism for Comlex Systems, by David Harel. Science
    of computer programming 8, 1987, pp231-274

  4. #4
    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: qstatemachine how to do conditional transitions based on concurrent state

    Quote Originally Posted by daviddrell View Post
    it was bad of me to assume that only those already familiar with the paper ( i.e the authors of QStateMachines) would be responding.
    If that was the case you would probably be waiting forever

    he describes a notational method for making state transitions in AND-parallel states where the transition (fig-19: beta(G)) is conditioned on the state of the adjacent sub-state-machine
    The problem with Qt's state machines is that it is not possible to directly ask the machine about what state it is in so to obtain information whether the sub-machine is in state "G" you need to cheat a bit by asking the machine to toggle an external flag that states whether it is in G state or not. Use a boolean property of some object and make the G state set this property to true and all other states to set it to false. Alternatively use QState::onExit() and QState::onEntry() of the G state to manipulate some external variable in a similar manner. Then you will be able to make some other transition active based on the value of this variable - either by reimplementing QAbstractTransition::eventTest() for the transition to check the variable or by using some higher-level transition class.

    To generalise -- you can use QAbstractTransition::eventTest() to implement any transition condition you want. The only problem is to provide an infrastructure for it. In your case you can do something like this:

    Qt Code:
    1. class InStateTransition : public QSignalTransition {
    2. Q_OBJECT
    3. Q_PROPERTY(bool canTrigger READ canTrigger WRITE setCanTrigger)
    4. public:
    5. InStateTransition(QState * sourceState = 0) : QSignalTransition(sourceState) {
    6. m_canTrigger = false;
    7. }
    8. void setCanTrigger(bool v) { m_canTrigger = v; }
    9. bool canTrigger() const { return m_canTrigger; }
    10. protected:
    11. bool eventTest(QEvent *e) {
    12. if(!QSignalTransition::eventTest(e))
    13. return false;
    14. return canTrigger();
    15. }
    16. private:
    17. bool m_canTrigger;
    18. };
    To copy to clipboard, switch view to plain text mode 

    Then you can use i.e.:
    Qt Code:
    1. stateG->assignProperty(someInStateTransition, "canTrigger", true);
    2. stateOtherThanG->assignProperty(someInStateTransition, "canTrigger", false);
    To copy to clipboard, switch view to plain text mode 

    And the transition will only fire when stateG is active.
    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.


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

    daviddrell (7th October 2010)

  6. #5
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    1

    Thumbs up Re: qstatemachine how to do conditional transitions based on concurrent state

    thank you for the excellent and complete response. I was afraid that would be the answer. But you built it for me so its not so bad.

  7. #6
    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: qstatemachine how to do conditional transitions based on concurrent state

    I didn't test it, it might not even compile But it's something to get you started.
    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.


Similar Threads

  1. Finding the current state of a QStateMachine
    By pherthyl in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2012, 15:14
  2. Replies: 1
    Last Post: 7th August 2010, 22:38
  3. Animated QTollBox transitions
    By NutMonkey in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2010, 13:57
  4. concurrent signals handling
    By s_stavrev in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2010, 15:16
  5. Concurrent progress reporting
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2008, 08:47

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.