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

Removed Loader component gets a null parent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.10.1
    • 5.4.1, 5.5.0
    • None
    • enterprise Qt 5.4.1, Mac 10.9, Qt Creator 3.3.0
    • 2eb2d6386da304cd1164264ae0bff685c796d89c

    Description

      I've only tested with Qt 5.4.1.

      If you remove a sourceComponent from a loader, the component's parent is set to null before that component is destroyed. This leads to an awkward need for extra null checking code to avoid a console error message. In my real-world code where I first encountered this issue, I've not found that this null actually breaks anything important but the error message is concerning.

      Consider the trivial QML below. When the user clicks the screen and the sourceComponent is set to null, I get the following in the console, where lines 13 and 14 refer to the "parent.width" and parent.height" expressions respectively:

      file:///Users/xxx/LoaderTest/LoaderTest.qml:13: TypeError: Cannot read property of null
      file:///Users/xxx/LoaderTest/LoaderTest.qml:14: TypeError: Cannot read property of null
      
      import QtQuick 2.4
      
      Rectangle {
          width: 360
          height: 360
      
          Loader {
              id: ldr
              anchors.fill: parent
          }
          
          property Component c: Rectangle {
              width: parent.width
              height: parent.height
              color: "pink"
          }
          
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  // toggle component on/off
                  ldr.sourceComponent = ldr.sourceComponent ? null : c;
              }
          }
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-47321
          # Subject Branch Project Status CR V

          Activity

            People

              aalpert Alan Alpert
              chrisdolan Chris Dolan
              Votes:
              3 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes