From fd7459a60c3b396984c948f244ec0996fba56837 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 17 Oct 2023 10:01:04 +0800 Subject: SignalSpy: manually disconnect from target signal when we're destroyed The SignalSpy is potentially destroyed before the target object, and since only the sender (target) being destroyed destroys a connection in QML, and not the receiver (SignalSpy), we need to manually disconnect. When QTBUG-118166 is implemented, we can remove this. Task-number: QTBUG-118163 Pick-to: 6.2 6.5 6.6 Change-Id: I76aaffba114a6db5b5aab6a2ff58541aa3b2e025 Reviewed-by: Fabian Kosmale --- src/qmltest/SignalSpy.qml | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/qmltest') diff --git a/src/qmltest/SignalSpy.qml b/src/qmltest/SignalSpy.qml index 029003c70f..93fde00edb 100644 --- a/src/qmltest/SignalSpy.qml +++ b/src/qmltest/SignalSpy.qml @@ -45,6 +45,16 @@ Item { id: spy visible: false + Component.onDestruction: { + // We are potentially destroyed before the target object, + // and since only the sender (target) being destroyed destroys a connection + // in QML, and not the receiver (us/"spy"), we need to manually disconnect. + // When QTBUG-118166 is implemented, we can remove this. + let signalFunc = target ? target[signalName] : null + if (signalFunc) + signalFunc.disconnect(spy.qtest_activated) + } + TestUtil { id: util } -- cgit v1.2.3