Uploaded image for project: 'Qt for MCUs'
  1. Qt for MCUs
  2. QTMCU-228

Cannot mix the ways to change states; "when" and assignment



    • All


      I checked these pages but couldn't find this limiation, so let me create a JIRA.

      1. https://doc.qt.io/QtForMCUs-2.5/qml-qtquick-state.html#name-prop
      2. https://doc.qt.io/QtForMCUs-2.2/default-state-limitations.html
      3. https://doc.qt.io/QtForMCUs-2.2/qtquick-statesanimations-states.html
      4. https://doc.qt.io/QtForMCUs-2.5/qtul-known-issues.html

      As far as I know, there are two ways to implement state transitions in QML; setting when property in State QML type or directly assigning the State's name property value to state property of Item-related QML types.

      I tried mixing both approaches in one app and it seems to be not working. 
      If this is technically impossible, it would be helpful to add this as one of the limitations.

      The sample project is attached to this ticket but here's the code to get the idea;


      // Define_and_Transition_States.qml
      import QtQuickRectangle {
          id: root
          color: "black"
          MouseArea {
              id: mouseArea
              anchors.fill: parent
              onPositionChanged: {
                  root.state = "blueScreen" // <-- using "assignment"
              onReleased: {
                  root.state = "" //<-- using "assignment"
              onPressed: {
          states: [
              State {
                  name: "redScreen"
                  when: mouseArea.pressed // <-- using "when"
                  PropertyChanges { target: root; color: "red" }
              State {
                  name: "blueScreen"
                  PropertyChanges { target: root; color: "blue" }


      When you launch the app and press the screen, the screen color changes to red, then by keep pressing and moving the cursor, the color changes to blue, finally, releasing the mosue cursor gets the color back to black.

      When you press the screen again, the color won't change to red, even though you see the debug message "pressed" in the Application Ouptput. You can keep pressing and moving the cursor to confirm the "assignment" approach still works.



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



            kwkim Kwangsub Kim
            mikio_hirai Mikio Hirai
            0 Vote for this issue
            3 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes