Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. State.active is false in State.onEntered()
QtWS25 Last Chance

State.active is false in State.onEntered()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
dsmstatemachinestate
2 Posts 2 Posters 925 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.
  • C Offline
    C Offline
    Christopher
    wrote on 27 Jun 2016, 15:06 last edited by
    #1

    Hi,

    when entering a state the state is not active in its onEntered function.

    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtQml.StateMachine 1.0
    
    Window {
        visible: true
    
        MainForm {
            id: mainForm
            anchors.fill: parent
    
            StateMachine {
    
                running: true
                initialState: state1
    
                State {
                    id: state1
                    SignalTransition {
                        signal: mainForm.mouseArea.clicked
                        targetState: state2
                    }
                }
    
                State {
                    id: state2
                    onEntered: {
                        console.log("state2.active: " + state2.active)
                    }
                }
            }
        }
    }
    

    Because in QAbstractStatePrivate::emitEntered() the entered() signal ist emited before activeChanged() is emited.

    void QAbstractStatePrivate::emitEntered()
    {
        Q_Q(QAbstractState);
        emit q->entered(QAbstractState::QPrivateSignal());
        if (!active) {
            active = true;
            emit q->activeChanged(true);
        }
    }
    

    Is there any reason?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jakob
      wrote on 11 Oct 2016, 09:29 last edited by
      #2

      Think of 'entering' a state as crossing the boundary between the outside into the box that corresponds to the new state. Or even more concrete, think of a state 'InsideTheHouse', and entering that state as going through some door. You need to enter before you are actually in the new state, just as you have to pass the door, in order to get to the actual state of 'InsideTheHouse'.

      This is a quite general pattern used by any state machine implementation I ever came across. I'm not entirely sure though whether the default texts about software patterns explain this very clearly though, as it really is more of an implementation detail than a generic pattern.

      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