diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-19 13:26:32 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-25 18:35:05 +0100 |
| commit | da6680cb2eeea4c845cffac0a0f9d24e30b1625c (patch) | |
| tree | 6411f8b6d49bf89fd8dc66232b9a07bc0c74b7a8 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | cc761e9c5a1c5249f4760c8e5e57755a3fe042ca (diff) | |
QmlCompiler: Implement resetting of properties
We piggy-back on the mechanism used to handle shadowable properties and
pass the value as QVariant. QVariant can hold undefined and the lookup
functions know how to handle it.
Pick-to: 6.7 6.6 6.5 6.2
Fixes: QTBUG-120512
Change-Id: I9bca4940256c82bdcf5540b956600eb420be363e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index f732998647..548ad20c2b 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -8,6 +8,7 @@ #include <data/enumproblems.h> #include <data/getOptionalLookup.h> #include <data/objectwithmethod.h> +#include <data/resettable.h> #include <data/weathermoduleurl.h> #include <data/withlength.h> @@ -186,6 +187,7 @@ private slots: void registerElimination(); void registerPropagation(); void renameAdjust(); + void resettableProperty(); void returnAfterReject(); void revisions(); void scopeIdLookup(); @@ -3837,6 +3839,27 @@ void tst_QmlCppCodegen::renameAdjust() QVERIFY(o); } +void tst_QmlCppCodegen::resettableProperty() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/resettable.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + + ResettableProperty *resettable = qobject_cast<ResettableProperty *>(o.data()); + QVERIFY(resettable); + + QCOMPARE(resettable->value(), 999); + QMetaObject::invokeMethod(resettable, "doReset"); + QCOMPARE(resettable->value(), 0); + + resettable->setValue(82); + QCOMPARE(resettable->value(), 82); + QMetaObject::invokeMethod(resettable, "doReset2"); + QCOMPARE(resettable->value(), 0); +} + void tst_QmlCppCodegen::returnAfterReject() { QQmlEngine engine; |
