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. [QML] History is not recorded by HistoryState

[QML] History is not recorded by HistoryState

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 719 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.
  • M Offline
    M Offline
    Montjet
    wrote on last edited by Montjet
    #1

    Hi,
    I have problem with HistoryState.
    For simple code:

    import QtQuick 2.11
    import QtQuick.Window 2.11
    import QtQuick.Controls 1.4
    import QtQml.StateMachine 1.11 as DSM
    
    Window {
        visible: true
        width: 120
        height: 120
        title: qsTr("Hello World")
    
        Button
        {
            id: button1
            anchors.left: parent.left
            width: parent.width / 2
            height: parent.height
            text: "button1"
        }
    
        Button
        {
            id: button2
            anchors.right: parent.right
            width: parent.width / 2
            height: parent.height
            text: "button2"
        }
    
        DSM.StateMachine
        {
            id: stateMachine
            initialState: beginState
            running: true
    
            DSM.HistoryState
            {
                id: historyState
                defaultState: state1
            }
    
            DSM.State
            {
                id: beginState
                onEntered: console.log("beginState")
    
                DSM.SignalTransition
                {
                    targetState: state1
                    signal: button1.clicked
                }
    
                DSM.SignalTransition
                {
                    targetState: state2
                    signal: button2.clicked
                }
            }
    
            DSM.State
            {
                id: state1
                onEntered: console.log("state1")
    
                DSM.SignalTransition
                {
                    targetState: state2
                    signal: button1.clicked
                }
            }
    
            DSM.State
            {
                id: state2
                onEntered: console.log("state2")
    
                DSM.SignalTransition
                {
                    targetState: historyState
                    signal: button1.clicked
                }
    
                DSM.SignalTransition
                {
                    targetState: beginState
                    signal: button2.clicked
                }
            }
    
            DSM.FinalState {
                id: finalState
            }
            onFinished: Qt.quit()
        }
    }
    
    

    A transition with a history state is a transition to default state (state1). History is not recorded, why?
    What's wrong with my code?

    Qt version: 5.11.1

    DiracsbracketD 1 Reply Last reply
    0
    • M Montjet

      Hi,
      I have problem with HistoryState.
      For simple code:

      import QtQuick 2.11
      import QtQuick.Window 2.11
      import QtQuick.Controls 1.4
      import QtQml.StateMachine 1.11 as DSM
      
      Window {
          visible: true
          width: 120
          height: 120
          title: qsTr("Hello World")
      
          Button
          {
              id: button1
              anchors.left: parent.left
              width: parent.width / 2
              height: parent.height
              text: "button1"
          }
      
          Button
          {
              id: button2
              anchors.right: parent.right
              width: parent.width / 2
              height: parent.height
              text: "button2"
          }
      
          DSM.StateMachine
          {
              id: stateMachine
              initialState: beginState
              running: true
      
              DSM.HistoryState
              {
                  id: historyState
                  defaultState: state1
              }
      
              DSM.State
              {
                  id: beginState
                  onEntered: console.log("beginState")
      
                  DSM.SignalTransition
                  {
                      targetState: state1
                      signal: button1.clicked
                  }
      
                  DSM.SignalTransition
                  {
                      targetState: state2
                      signal: button2.clicked
                  }
              }
      
              DSM.State
              {
                  id: state1
                  onEntered: console.log("state1")
      
                  DSM.SignalTransition
                  {
                      targetState: state2
                      signal: button1.clicked
                  }
              }
      
              DSM.State
              {
                  id: state2
                  onEntered: console.log("state2")
      
                  DSM.SignalTransition
                  {
                      targetState: historyState
                      signal: button1.clicked
                  }
      
                  DSM.SignalTransition
                  {
                      targetState: beginState
                      signal: button2.clicked
                  }
              }
      
              DSM.FinalState {
                  id: finalState
              }
              onFinished: Qt.quit()
          }
      }
      
      

      A transition with a history state is a transition to default state (state1). History is not recorded, why?
      What's wrong with my code?

      Qt version: 5.11.1

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @Montjet
      I think you are not using the history state correctly.

      A history state should be defined inside a parent state, along with other children states
      as it is used to restore the child state of its parent state.

      You declare your history state outside any parent state...

      Have a look at this example:
      http://doc.qt.io/qt-5/qmlstatemachine.html#using-history-states

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Montjet
        wrote on last edited by
        #3

        Thank you, it works.

        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