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. QState::entered behaviour

QState::entered behaviour

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 832 Views 1 Watching
  • 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.
  • U Offline
    U Offline
    unzu
    wrote on last edited by
    #1

    Hi,

    I've got a question regarding the QState-class.
    I have created my own class which is a child of the QState-class by inheritance because I want to fire some special events whenever a state is entered et cetera.

    In the constructor of the qstate-class I connect a lambda-function to the entered-signal:

    connect(this, &QState::entered, this, [this](){
            qInfo() << this->active();
    }, Qt::DirectConnection);
    

    I would expect it to always print true - however it is always false?
    How am I supposed to interpret that?

    1. The state is in the process of being entered, therefor not active yet?
    2. Am I messing it up by specifying Qt::DirectConnection? If I use Qt::QueuedConnection, it prints "true", as I would expect it..?

    Thanks in advance,
    Unzu

    KroMignonK 1 Reply Last reply
    0
    • U unzu

      Hi,

      I've got a question regarding the QState-class.
      I have created my own class which is a child of the QState-class by inheritance because I want to fire some special events whenever a state is entered et cetera.

      In the constructor of the qstate-class I connect a lambda-function to the entered-signal:

      connect(this, &QState::entered, this, [this](){
              qInfo() << this->active();
      }, Qt::DirectConnection);
      

      I would expect it to always print true - however it is always false?
      How am I supposed to interpret that?

      1. The state is in the process of being entered, therefor not active yet?
      2. Am I messing it up by specifying Qt::DirectConnection? If I use Qt::QueuedConnection, it prints "true", as I would expect it..?

      Thanks in advance,
      Unzu

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @unzu I am not comfortable with QState (I never use it), but in documentation I can see a signal activeChanged().
      This tells me that entering a state does not obviously means the state is active.

      As side not, in your connect() sender and receiver are in same thread (they are the same also ;)) so the connection will be per default direct.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        unzu
        wrote on last edited by
        #3

        Thanks for the response!
        I decided to use the activeChanged()-Signal, works fine now.
        Btw, how did you highlight the "QState" and "activeChanged()"???
        I can't figure it out :P

        KroMignonK 1 Reply Last reply
        0
        • U unzu

          Thanks for the response!
          I decided to use the activeChanged()-Signal, works fine now.
          Btw, how did you highlight the "QState" and "activeChanged()"???
          I can't figure it out :P

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @unzu said in QState::entered behaviour:

          I can't figure it out :P

          well there was some times ago, a little help, which I can find again.
          There are "common" wiki escapes sequences like:

          • `keyword` ==> keyword
          • *cursive* ==> cursive
          • **bold** ==> bold
          • ***bold and cursive*** ==> bold and cursive

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Are you doing anything else beside connecting that lambda ? If so, you are using a canon to kill a fly.

            There's rarely a need to subclass the QState class.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • U Offline
              U Offline
              unzu
              wrote on last edited by
              #6

              No, I'm subclassing because there is a lot more happening in my substates.
              I've just reduced my question to the lambda expression to improve clearness on what my problem is.

              Thanks
              Unzu

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Pure curiosity, would you mind telling a bit more about the design of your subclass ?

                Usually, you have objects that are "controlled" by the state like shown in the examples of the framework.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • U Offline
                  U Offline
                  unzu
                  wrote on last edited by
                  #8

                  @SGaist said in QState::entered behaviour:

                  Pure curiosity, would you mind telling a bit more about the design of your subclass ?

                  Usually, you have objects that are "controlled" by the state like shown in the examples of the framework.

                  Hi, I completely forgot to check for responses because I marked the thread as finished, sorry.
                  I put some functions in the sub-classes which I want to react to events from 'outside', but only when the state is active.
                  Of course there is no need to put a class around them, however by doing so, I've got the code and functions bundled together where they belong to: the specific states. That gives me some kind of overview over the mess which I am creating.. \o/

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Ok, I see.

                    I would rather have an "enabled" property or something like that on the "controller class" connected to the state so that the object can also be tested without the full state machine.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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