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

An object that is stored in an array and later destroy()'d is not set to null, but is instead "corrupt"

    XMLWordPrintable

Details

    Description

      As found in https://codereview.qt-project.org/#/c/180025/ and discussed in the workaround, an object that is in array will become "corrupt" when destroyed and then later accessed via that array.

      import QtQuick 2.5
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.0
      
      Window {
          id: window
          visible: true
          width: 400
          height: 400
      
          property var obj
          property var collection: []
      
          Component.onCompleted:  {
              // create
              obj = Qt.createQmlObject("import QtQuick 2.0; Rectangle {}", this)
              collection[0] = Qt.createQmlObject("import QtQuick 2.0; Rectangle {}", this)
              // destroy
              obj.destroy()
              collection[0].destroy()
          }
      
          Timer {
              interval: 1000
              repeat: true
              running: true
              onTriggered: {
                  console.log(obj, collection[0])
              }
          }
      }
      
      

      Quoting mbrasser:

      The output is: qml: null TypeError: Type error i.e. it appears we correctly set individual properties to null when the object is destroyed, but not members of an Array. Simon, is that expected?

      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
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes