aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-10-18 12:09:19 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-10-24 18:27:03 +0000
commit35630eef3d384c29c567566e5643123f58615dfe (patch)
tree935421f88e0aee0c5ff814e6de460456dabbaebe /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent8e3547fdaf52870534bd1dc907f9bc32559827b7 (diff)
QtQml: Unify detaching behavior for all reference objects
All reference objects should be detached when written to a property of a QML-defined type. This is in line with what happens if you write the same object to a property of a C++-defined type and doing anything else makes very little sense. In particular, before this change, the behavior differed between ahead-of-time compiled code and interpreted code, between writing to "var" properties and writing to typed properties, and between different kinds of lists. Now everything we recognize as reference object always gets detached when writing to a property. [ChangeLog][QtQml][Important Behavior Changes] Writing a list or value type to a QML-declared property now always detaches this same list or value from any locals or other properties you may have read it from. Therefore, subsequent changes to its "source" will not affect it anymore. This is in line with what we do to C++-declared properties. Fixes: QTBUG-127957 Change-Id: Icdf188ef29d28e5d3aaa8219cc003e07e8813f38 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 70ad1cb926..cf4a673722 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -84,6 +84,7 @@ private slots:
void dateConstruction();
void dateConversions();
void deadShoeSize();
+ void detachOnAssignment();
void dialogButtonBox();
void enumConversion();
void enumFromBadSingleton();
@@ -1536,6 +1537,30 @@ void tst_QmlCppCodegen::deadShoeSize()
QCOMPARE(o->property("shoeSize").toInt(), 0);
}
+void tst_QmlCppCodegen::detachOnAssignment()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/detachOnAssignment.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+
+ BirthdayPartyAttached *b = static_cast<BirthdayPartyAttached *>(
+ qmlAttachedPropertiesObject<BirthdayParty>(o.data()));
+ QVERIFY(b);
+ QCOMPARE(o->property("d").value<QDateTime>().date().year(), 1997);
+ QCOMPARE(b->rsvp().date().year(), 2001);
+
+ Person *p = qvariant_cast<Person *>(o->property("person"));
+ QVERIFY(p);
+
+ QCOMPARE(o->property("r").value<QRectF>(), QRectF(2, 3, 4, 5));
+ QCOMPARE(p->area(), QRectF(22, 3, 4, 5));
+
+ QCOMPARE(o->property("v").value<QVariantList>()[0], QStringLiteral("a"));
+ QCOMPARE(p->things()[0], QStringLiteral("c"));
+}
+
void tst_QmlCppCodegen::dialogButtonBox()
{
QQmlEngine engine;