Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91186

[REG 5.12.9->5.14.2] Using the when property of the State QML Type leads to the default state being applied between state changes.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 5.14.2, 5.15.2, 5.15.3, 6.0.0, 6.1.0 Alpha
    • None

    Description

      Relying on the when property of the State QML Type to handle state changes, leads to the default "" state being applied.

      Consider the following example: 

      Item {
          id: item
          anchors.fill: parent
      
          property bool toggle
      
          Button {
              anchors.fill: parent
              onClicked: item.toggle = ! item.toggle
          }
      
          states: [
              State {
                  name: "true"
                  when: item.toggle
              },
              State {
                  name: "false"
                  when: ! item.toggle
              }
          ]
      
          onStateChanged: {
              console.log("state:", state, "toggle:", toggle)
          }
      }
      

      The expected output when clicking the Button twice is:

      qml: state: false toggle: false
      qml: state: true toggle: true
      qml: state: false toggle: false
      

      where the first line appears at startup. This output is obtained with QT 5.12.9.

      With QT 5.15.2 one gets the following output: 

      qml: state: false toggle: false
      qml: state:  toggle: true
      qml: state: true toggle: true
      qml: state: false toggle: false
      

      The second line shows that the transition from the "false" state to the "true" state temporarily applies the default "" state in between. This in particular leads to transitions from: "false" being stopped.

      When there are only 2 states a workaround is to specify "when: true" in the second state in the list. For QT 5.12.4 until QT 5.14.0 even that does not work, because of QTBUG-76838, but "when: 1 == 1" works in these versions. For more than 2 states one needs to handle state changes in javascript.

      Windows: reproduced, iOS: reproduced

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              paulpeters Paul Peters
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes