aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data
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/data
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/data')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/detachOnAssignment.qml25
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 7d6d7cd088..f8966b9949 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -127,6 +127,7 @@ set(qml_files
dateConversions.qml
deadShoeSize.qml
deadStoreLoop.qml
+ detachOnAssignment.qml
dialog.qml
dialogButtonBox.qml
dynamicscene.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/detachOnAssignment.qml b/tests/auto/qml/qmlcppcodegen/data/detachOnAssignment.qml
new file mode 100644
index 0000000000..c13d1c90ae
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/detachOnAssignment.qml
@@ -0,0 +1,25 @@
+pragma Strict
+import QtQml
+import TestTypes
+
+QtObject {
+ property var d
+ property var r
+ property var v
+
+ property Person person: Person { id: person }
+
+ Component.onCompleted: {
+ BirthdayParty.rsvp = new Date(1997, 2, 3, 4, 5);
+ d = BirthdayParty.rsvp
+ BirthdayParty.rsvp = new Date(2001, 5);
+
+ person.area = { x: 2, y: 3, width: 4, height: 5};
+ r = person.area;
+ person.area.x = 22;
+
+ person.things = ["a", 3, new Date(), this, null];
+ v = person.things;
+ person.things[0] = "c";
+ }
+}