diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-11-06 15:21:24 +0100 |
---|---|---|
committer | Sami Varanka <sami.varanka@qt.io> | 2023-11-15 18:54:42 +0200 |
commit | 9331947a9de4e500de7db56b096618713c947419 (patch) | |
tree | 3685546c086f530a8c6c52476c40ba827d92b85d /tests/auto/qml/qqmlecmascript/data | |
parent | a1a0241946906b6ae81e5a3926c6af925d8b8073 (diff) |
Detect slot object if explicitly provided
If explicitly context is given to function when connecting, it is used
as the receiver. Then when the context is destroyed, the connection
will also be cleared.
Pick-to: 6.6
Fixes: QTBUG-29676
Change-Id: Iec9318132245094603f71e3e6279d65c8021cb7e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/data')
4 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.8.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.8.qml new file mode 100644 index 0000000000..7d43aa6c05 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.8.qml @@ -0,0 +1,21 @@ +import Qt.test +import QtQuick + +Item { + id: root + property int count: 0 + signal someSignal + + property Item item: Item { + id: contextItem + function test() { + count++; + } + } + + function itemDestroy() { + contextItem.destroy() + } + + Component.onCompleted: root.someSignal.connect(contextItem, contextItem.test); +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnect.9.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnect.9.qml new file mode 100644 index 0000000000..1123edf3f7 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnect.9.qml @@ -0,0 +1,30 @@ +import Qt.test +import QtQuick + +MyQmlObject { + id: root + property int a: 0 + + signal someSignal + + function disconnectSignal() { + root.someSignal.disconnect(other.MyQmlObject, root.test) + } + + function destroyObj() { + other.destroy() + } + + function test() { + other.MyQmlObject.value2++ + root.a = other.MyQmlObject.value2 + } + + property MyQmlObject obj + obj: MyQmlObject { + id: other + MyQmlObject.value2: 0 + } + + Component.onCompleted: root.someSignal.connect(other.MyQmlObject, root.test) +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptConnectSingleton.qml b/tests/auto/qml/qqmlecmascript/data/scriptConnectSingleton.qml new file mode 100644 index 0000000000..f666945b33 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptConnectSingleton.qml @@ -0,0 +1,21 @@ +import QtQuick +import Test + +Item { + id: root + + property int a: 0 + signal mySignal + + function test() { + MyInheritedQmlObjectSingleton.value++ + root.a = MyInheritedQmlObjectSingleton.value + } + + function disconnectSingleton() { + root.mySignal.disconnect(MyInheritedQmlObjectSingleton, root.test) + } + + Component.onCompleted: root.mySignal.connect(MyInheritedQmlObjectSingleton, + root.test) +} diff --git a/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.5.qml b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.5.qml new file mode 100644 index 0000000000..9d24fa85ae --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/scriptDisconnect.5.qml @@ -0,0 +1,19 @@ +import Qt.test +import QtQuick + +Item { + id: root + property int count: 0 + signal someSignal + signal disconnectSignal + + property Item item: Item { + id: contextItem + function test() { + count++; + } + } + + Component.onCompleted: root.someSignal.connect(contextItem, contextItem.test); + onDisconnectSignal: { root.someSignal.disconnect(contextItem, contextItem.test); } +} |