Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.11, 6.2.6
-
c249edb83fa67b3e5f711b28923397e66876182d
Description
Steps to reproduce
- Build and run the example project
- Click "Reload"
Code
// SubItem.qml import QtQuick 2.15 Item { Text { anchors.top: parent.top text: "SubItem" onParentChanged: console.log(this, "has a new parent:", parent) Component.onCompleted: console.log("Hello Text!\t", this) Component.onDestruction: console.log("G'bye Text!\t", this) } Component.onCompleted: console.log("Hello Item!\t", this) Component.onDestruction: console.log("G'bye Item!\t", this) }
// main.qml import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 Window { id: root width: 640 height: 480 visible: true property Component comp: SubItem{} Column{ Button { text: "Reload" onClicked: { loader.active = false loader.active = true } } Loader { id: loader sourceComponent: Item { id: loadedItem width: 50 height: 50 Component.onCompleted: root.comp.createObject(loadedItem) } } } }
Outcomes
At startup:
qml: QQuickText(0x2c83c0f8250) has a new parent: SubItem_QMLTYPE_3(0x2c83c0f8a30) qml: Hello Item! SubItem_QMLTYPE_3(0x2c83c0f8a30) qml: Hello Text! QQuickText(0x2c83c0f8250)
Upon clicking "Reload":
qml: QQuickText(0x2c8425f6aa0) has a new parent: SubItem_QMLTYPE_3(0x2c8425f6740) qml: Hello Item! SubItem_QMLTYPE_3(0x2c8425f6740) qml: Hello Text! QQuickText(0x2c8425f6aa0) qml: G'bye Text! QQuickText(0x2c83c0f8250) qml: G'bye Item! SubItem_QMLTYPE_3(0x2c83c0f8a30) qml: [object Object] has a new parent: undefined qrc:/SubItem.qml:5: TypeError: Cannot read property 'top' of undefined
The last 4 lines show that even after the Text object has been destroyed, the Text's `onParentChanged` signal handler still runs and its `anchors.top` property binding is still re-evaluated, which should not happen.
Notes
Qt 6.3.2 and 6.4.0 are not affected by this issue (The last 2 lines of the output don't appear). It would be good to backport the fix to Qt 5.15 LTS and Qt 6.2 LTS.
Attachments
Issue Links
- relates to
-
QTBUG-107850 Crash on QQuickItem destruction
- Closed
-
QTBUG-108213 Unexpected visibleChanged signals on QQuickItem destruction
- Closed