diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-05-06 14:37:55 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-05-10 19:26:02 +0000 |
commit | 1b5463ccfbe3fde74adf8e0651662cad1979c216 (patch) | |
tree | 361cbdeef782d36b0a38660b07be1f71e00cf182 /tests | |
parent | 3c57b9e07713dd504ad64068dfe9159e3380ac77 (diff) |
V4: Do not write back value type references on const method calls
The property setters can have side effects. We should only call them if
really necessary. We don't have to write back after calling const
methods.
Fixes: QTBUG-93480
Change-Id: I53a246edd37b7f0c31f0e0effe5dfa996548f74c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index bc21238c7b..9c732e4ce3 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1868,7 +1868,7 @@ struct Foo { QML_ANONYMOUS public: int val = 1; - Q_INVOKABLE int value() { return val; } + Q_INVOKABLE int value() const { return val; } Q_INVOKABLE void setValue(int v) { val = v; } }; @@ -1880,10 +1880,12 @@ class S : public QObject Q_PROPERTY(Foo foo READ foo WRITE setFoo NOTIFY fooChanged); QML_ELEMENT public: + int writeCount = 0; Foo f; Foo foo() { return f; } void setFoo(Foo f) { + ++writeCount; this->f = f; emit fooChanged(); } @@ -1920,6 +1922,10 @@ void tst_qqmlvaluetypes::writeBackOnFunctionCall() QVERIFY(!o.isNull()); QCOMPARE(o->property("a").toInt(), 3); QCOMPARE(o->property("b").toInt(), 3); + S *s = qvariant_cast<S *>(o->property("s")); + QVERIFY(s); + // f.value() should not write back. + QCOMPARE(s->writeCount, 2); } #undef CHECK_TYPE_IS_NOT_VALUETYPE |