aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-05-04 17:00:16 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-05-05 22:15:44 +0200
commit1dc4bdbabfed1eb73b563a77810ceb00a8fd6fca (patch)
tree160c2cce24848faf2bce1e464bcef2111ce3f9d1 /tests
parent21463aa204bea6c92f2864156fc133c44e8d5d6f (diff)
V4: Write back value type references after function calls
If we call a function on a value type reference we have to assume that the value has changed. Therefore, we need to write back, just like we do when writing a property on the reference. Fixes: QTBUG-91783 Pick-to: 6.1 5.15 Change-Id: I6d2e957997d64e40e42eb5210350b6592a92ee26 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index 47387ad837..bc21238c7b 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -100,6 +100,7 @@ private slots:
void scarceTypes();
void nonValueTypes();
void char16Type();
+ void writeBackOnFunctionCall();
private:
QQmlEngine engine;
@@ -1862,6 +1863,65 @@ void tst_qqmlvaluetypes::char16Type()
QCOMPARE(scoped->toQString(), "a");
}
+struct Foo {
+ Q_GADGET
+ QML_ANONYMOUS
+public:
+ int val = 1;
+ Q_INVOKABLE int value() { return val; }
+ Q_INVOKABLE void setValue(int v) { val = v; }
+};
+
+Q_DECLARE_METATYPE(Foo);
+
+class S : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Foo foo READ foo WRITE setFoo NOTIFY fooChanged);
+ QML_ELEMENT
+public:
+ Foo f;
+ Foo foo() { return f; }
+ void setFoo(Foo f)
+ {
+ this->f = f;
+ emit fooChanged();
+ }
+ Q_INVOKABLE Foo get() { return f; }
+signals:
+ void fooChanged();
+};
+
+void tst_qqmlvaluetypes::writeBackOnFunctionCall()
+{
+ qmlRegisterTypesAndRevisions<Foo>("WriteBack", 1);
+ qmlRegisterTypesAndRevisions<S>("WriteBack", 1);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQml 2.15\n"
+ "import WriteBack 1.0\n"
+ "QtObject {\n"
+ " property S s: S {}\n"
+ " property int a: -1\n"
+ " property int b: -1\n"
+ " Component.onCompleted: {\n"
+ " var f = s.foo\n"
+ " f.setValue(3)\n"
+ " s.foo = f\n"
+ " a = f.value()\n"
+ " f = s.get()\n"
+ " f.setValue(3)\n"
+ " b = f.value()\n"
+ " }\n"
+ "}\n", QUrl());
+ QVERIFY2(component.isReady(), component.errorString().toUtf8());
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->property("a").toInt(), 3);
+ QCOMPARE(o->property("b").toInt(), 3);
+}
+
#undef CHECK_TYPE_IS_NOT_VALUETYPE
QTEST_MAIN(tst_qqmlvaluetypes)