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

When PropertyChanges is in a Loader, it cannot rebind a property outside the Loader without using `target`

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9.0
    • None
    • Operating System: openSUSE Tumbleweed 20250602
      KDE Plasma Version: 6.3.5
      KDE Frameworks Version: 6.14.0
      Qt Version: 6.9.0
      Kernel Version: 6.15.0-1-default (64-bit)
      Graphics Platform: X11
    • Linux/X11

    Description

      Run the following code and flick the switch:

      pragma ComponentBehavior: Bound
      
      import QtQuick
      import QtQuick.Controls
      
      Window {
          id: root
          width: 640
          height: 480
          visible: true
      
          title: "Default window title"
      
          Loader {
              id: desktopMainContent
              anchors.centerIn: parent
      
              sourceComponent: Item {
                  Switch {
                      id: mySwitch
                      anchors {
                          verticalCenter: parent.verticalCenter
                          right: parent.horizontalCenter
                      }
                  }
                  Label {
                      id: label
                      anchors {
                          verticalCenter: parent.verticalCenter
                          left: parent.horizontalCenter
                      }
                      text: "Default label text"
                  }
      
                  states: State {
                      name: "inCustomState"
                      when: mySwitch.checked
                      changes: [
                          PropertyChanges {
                              //! [0]
                              root.title: "In state"
                              //! [0]
      
                              //! [1]
                              // target: root
                              // title: "In state"
                              //! [1]
                          },
                          PropertyChanges {
                              label.text: root.title
                          }
                      ]
                  }
              }
          }
      }
      
      

      You will notice that the window title doesn't change as expected. In the application output I get qrc:/qt/qml/playground/Main.qml:39:21: QML PropertyChanges: Cannot assign to non-existent property "root.title".

      If you comment out the code in [0] and uncomment the code in [1], the app works as expected.

      The issue here is that the code in [1] triggers Quick.property-changes-parsed in qmllint. So either the the code in [0] should work as expected, or the qmllint issue should have an exception for PropertyChanges in a Loader.

      Attachments

        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
            jackh Jack Hill
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes