diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-02-15 11:51:25 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-02-15 14:23:16 +0000 |
commit | b2420780df98cb3c98553da18a5b1bc5b64e9e83 (patch) | |
tree | c5d19d6091e378c082fde5da1be6e4eb7d87c691 /tests | |
parent | d19127807c193d612c6fee4f3418a8c8af9d262c (diff) |
Correctly set this object when calling scope/context functions
When a function is called that is in a QML scope or a QML context, set
the 'this' object to the QML scope.
Note: this patch is 5.9 specific. 5.11 has a similair issue, but the
implementation is quite different, so that needs a separate fix.
Task-number: QTBUG-59357
Change-Id: Ia78e012d413c40a094e957f4020502cd055ac286
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml b/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml new file mode 100644 index 0000000000..e3c99e70e1 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/thisInQmlScope.qml @@ -0,0 +1,10 @@ +import QtQml 2.2 +QtObject { + property int x: 42 + property int y: 0 + function g(){ + y = this.x; + } + property var f: g + Component.onCompleted: f() +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 83151fb6e2..292403bcbb 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -273,6 +273,8 @@ private slots: void lowercaseTypeNames(); + void thisInQmlScope(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -4604,6 +4606,19 @@ void tst_qqmllanguage::lowercaseTypeNames() QCOMPARE(qmlRegisterSingletonType<QObject>("Test", 1, 0, "lowerCaseTypeName", nullptr), -1); } +void tst_qqmllanguage::thisInQmlScope() +{ + QQmlEngine engine; + + QQmlComponent component(&engine, testFileUrl("thisInQmlScope.qml")); + QTRY_VERIFY(component.isReady()); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + QCOMPARE(o->property("x"), QVariant(42)); + QCOMPARE(o->property("y"), QVariant(42)); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |