aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-12-22 14:45:04 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-01-02 21:50:34 +0100
commit3fd3a2a9d06505d549cc4a7c18819a17c6622dfd (patch)
treeaa266f8c45a9f81537a3820223f04387e57ddeb1 /tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml
parente39b4572c272f8a0a7be048a24808cb028480e82 (diff)
QObjectWrapper: Fix calling attached methods on different objects
You can generally store a method in a value and call it on a different object. However, since we've ignored the thisObject basically forever, we cannot just accept it right away. Add an opt-in mechanism via a pragma that allows you to pass (implicitly via context or explicitly via call()) specific thisObjects to QObject methods. Fixes: QTBUG-109585 Pick-to: 6.5 Change-Id: I4c81b8ecf6317af55104ac9ebb62d98862ff24e7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml')
-rw-r--r--tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml b/tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml
new file mode 100644
index 0000000000..2af2e04352
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/objectAndGadgetMethodCallsAcceptThisObject.qml
@@ -0,0 +1,33 @@
+pragma NativeMethodBehavior: AcceptThisObject
+import ValueTypes
+import StaticTest
+import QtQml
+
+QtObject {
+ id: self
+
+ property base v1
+ property derived v2
+
+ property var valueTypeMethod: v1.report
+
+ property var qtMethod: Qt.rect
+
+ property rect badRect: self.qtMethod(1, 2, 3, 4)
+ property rect goodRect1: qtMethod.call(undefined, 1, 2, 3, 4)
+ property rect goodRect2: qtMethod.call(Qt, 1, 2, 3, 4)
+
+ property string badString: self.valueTypeMethod()
+ property string goodString1: valueTypeMethod.call(undefined)
+ property string goodString2: valueTypeMethod.call(v1)
+ property string goodString3: valueTypeMethod.call(v2)
+
+ property string goodString4: toString.call(Qt)
+ property string badString2: toString.call(goodRect1)
+
+ property var mm: OriginalSingleton.mm
+ property int badInt: self.mm()
+ property int goodInt1: mm.call(undefined)
+ property int goodInt2: mm.call(OriginalSingleton)
+ property int goodInt3: mm.call(DerivedSingleton)
+}