aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-12-09 16:06:34 +0100
committerUlf Hermann <ulf.hermann@qt.io>2025-12-10 20:16:35 +0100
commitdef060a2ed60d323fafd4aa90777dd1f5d65543f (patch)
treef56d1e062eef4ace874a9667bb3a18e8236ead37 /src
parentaca98edecfc71ffb642abc003ddcd0d3270fc280 (diff)
QtQml: Update docs about constructible value types
You shouldn't use type assertions to create value types. That was a terrible idea. We can document the interaction with the 'new' operator now, though. Task-number: QTBUG-124662 Pick-to: 6.11 6.10 6.8 Change-Id: I94dbf47cfd72ef20a2d4758450634708590f8fec Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Elias Steurer <i@kelteseth.net>
Diffstat (limited to 'src')
-rw-r--r--src/qml/doc/src/cppintegration/macros.qdoc26
1 files changed, 5 insertions, 21 deletions
diff --git a/src/qml/doc/src/cppintegration/macros.qdoc b/src/qml/doc/src/cppintegration/macros.qdoc
index 795856bc17..f360c966bc 100644
--- a/src/qml/doc/src/cppintegration/macros.qdoc
+++ b/src/qml/doc/src/cppintegration/macros.qdoc
@@ -811,17 +811,16 @@
}
\endqml
- If you make value types \l{ValueTypeBehavior}{addressable}, you can
- use such a type in a \l{Type annotations and assertions}{type assertion}
- to explicitly construct it:
+ Since Qt 6.8, if you import the QML module the value type belongs to into a
+ namespace, you can use JavaScript's \c new operator to instantiate it.
\qml
- pragma ValueTypeBehavior: Addressable
+ import MyModule as MM
QtObject {
function process(d: real) {
- let v = d as myValueType;
- // v is a myValueType now, not a number
+ let v = new MM.myValueType(d);
+ // v is a myValueType now
}
}
\endqml
@@ -877,20 +876,5 @@
}
\endqml
- If you make value types \l{ValueTypeBehavior}{addressable}, you can
- use such a type in a \l{Type annotations and assertions}{type assertion}
- to explicitly construct it:
-
- \qml
- pragma ValueTypeBehavior: Addressable
-
- QtObject {
- function process(d: real) {
- let v = {d: d, e: objectName} as myValueType;
- // v is a myValueType now
- }
- }
- \endqml
-
\sa QML_VALUE_TYPE QML_CONSTRUCTIBLE_VALUE
*/