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

Changing Loader source breaks references on QML objects: 'ReferenceError: ... is not defined'

    XMLWordPrintable

Details

    Description

      I found a regression in Qt 5.10 when using Loader.

       

      I have an app with main window, containing some properties and a loader. Loader loads few app's screens.

       

      ApplicationWindow {
          id: mainwindow
          visible: true
          title: qsTr("Loader test")

          property string backgroundSource : "qrc:/background1.png"

          Loader {
              id: loader
              anchors.fill: parent
              source: "qrc:/screen1.qml"
          }
      }

       

      There is some code which I have to execute after loader changed its source. In this code I use properties of the main window. For example:

              MouseArea {
                  id: area
                  anchors.fill: parent
                  onClicked: {
                      console.log('Button on screen 1 pressed')
                      console.log('Setting loader source')
                      loader.setSource('qrc:/screen2.qml')
                      console.log('Changing background')
                      mainwindow.backgroundSource = 'qrc:/background2.png'
                      console.log('Everything is ok')
                  }
              }

       

      Everything was ok up to Qt 5.10.0:

      D libloader_test.so: qrc:/screen1.qml:31 (onClicked): qml: Button on screen 1 pressed
      D libloader_test.so: qrc:/screen1.qml:32 (onClicked): qml: Setting loader source
      D libloader_test.so: qrc:/screen1.qml:34 (onClicked): qml: Changing background
      D libloader_test.so: qrc:/screen1.qml:36 (onClicked): qml: Everything is ok

       

      But since Qt 5.10.1 I have this error:

      D libloader_test.so: qrc:/screen1.qml:31 (onClicked): qml: Button on screen 1 pressed
      D libloader_test.so: qrc:/screen1.qml:32 (onClicked): qml: Setting loader source
      D libloader_test.so: qrc:/screen1.qml:34 (onClicked): qml: Changing background
      W libloader_test.so: qrc:/screen1.qml:35 ((null)): qrc:/screen1.qml:35: ReferenceError: mainwindow is not defined

       

      Attached small example with code to reproduce bug

       

      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
              a.antsev Alexander Antsev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes