Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Software Architecture with (Q)state machine
Forum Update on Monday, May 27th 2025

Software Architecture with (Q)state machine

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ngrosjean
    wrote on last edited by
    #1

    Hello,

    I'm working on an embedded software under Linux with the help of Qt. I have some experience on this, but this time I try to manage the state machine with QStateMachine api.

    My software is based on model / view architecture, and I divide the software on module and submodule. More or less a module contains models and another views. I put the state on a third module, and I believe that the state module should be independant from the views and models. Having I look on the Qt state api, I have some question because with my architecture I can't use the QEventTransition and the QSignalTransition as those two classes seem to be deeply dependant of the event sender. Am I right? So I have to create my own transition class from the QAbstractTransition...

    My questions are:

    • do you agree with my point of view or do you think a QStateMachine should be deeply linked to the rest of the software or did I miss something?
    • How do you use the QStateMachine api yourself?

    Thanks,

    Nicolas

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      [quote author="ngrosjean" date="1282759541"]* do you agree with my point of view or do you think a QStateMachine should be deeply linked to the rest of the software or did I miss something?[/quote]

      Note that this isn't deeply linked. All you know is something about an object (and nearly everything is an object in Qt). It does make sense to me that if something happens, it is triggered by an object of sorts. However it is always possible to create your own derivative of QAbstractTransition.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ngrosjean
        wrote on last edited by
        #3

        Thanks for your reply. I see your point of view and I'm agree you only need a QObject pointer (like for signal / slot), but :

        • where did you contruct your QEventTransition? Is it correct to think it is on the state machine itself?...

        • ...then in this case you should give a reference (even as QObject) of all potentiel "state event sender"!

        Perhaps I'm just wrong to mix Qt Model / View with Qt StateMachine Api...

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          I'm planning to do some work with the API, but haven't done much so far (lots of other stuff to do). So all I say is based on the docs.

          It seems to me however that given the current API, you would have some sort of wrapper around your state machine that allows you to register classes. This would allow you to implement the state machine differently (the old fashioned enum way for example) without having to adapt your interface.

          It doesn't seem logical to me to have a GUI element managing a state machine unless it works on that particular GUI element only (animations).

          To be able to use the event transition you would have to know the pointer to the state machine however; the application wouldn't know where to send it otherwise.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • N Offline
            N Offline
            ngrosjean
            wrote on last edited by
            #5

            My state machine will only be managed by the way of Event. I made a minimum subclasse of QAbstractTransition :

            @class CSubTransition : public QAbstractTransition
            {
            public :
            CSubTransition(QState* pStartState, const QEvent::Type eventID);
            virtual ~CSubTransition();

            protected :
                virtual bool eventTest(QEvent *e) ;
                virtual void onTransition(QEvent *e);
            
            private:
                const QEvent::Type a_EVENT_ID;
            

            };@

            with on .cpp file:

            @bool CSubTransition::eventTest(QEvent *e)
            {
            return (a_EVENT_ID == e->type());
            };@

            ... and then just listing my "state event" from my UML Diagram into a header and create all transitions instance on my main state machine.

            Now, as you said, somewhere far away in my code I should have something like @pMyStateMachine->PostEvent(MY_EVENT)@... that means a pointer to the state machine base class.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sabrog
              wrote on last edited by
              #6

              [offtopic]I found bug. While you dont select "MY EVENT" code, it show incorrect in Firefox, without "_" character.[/offtopic]

              QT - Apple QuickTime
              Qt - Nokia's Qt Development Frameworks
              Apple is a competitor of Nokia, so QT != Qt

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved