aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsvalue.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-08-18 14:55:34 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-08-22 16:32:03 +0200
commit0d67aad01c7f4daaf63d416c380c1f61586fd4da (patch)
treea9e9909c271f7983e677bd0ccd25b241e0c36295 /src/qml/jsapi/qjsvalue.cpp
parent4a0735e5eda232ab1ea5d9e118a7ec5a9954f6f6 (diff)
QtQml: Return QVariant{Map|Hash} as-is when converting QJSValue
If we know that the object contained in a QJSValue was created from a QVariantMap or QVariantHash, it makes no sense to hide that by producing the JavaScript representation of it. The user is calling toVariant() to obtain a usable QVariant after all. [ChangeLog][QtQml][Important Behavior Changes] QJSValue::toVariant() now returns a QVariantMap or QVariantHash for JavaScript objects created from a QVariantMap or QVariantHash, even if you tell it to RetainJSObjects via the "behavior" argument. There is no conversion in this case, after all. Change-Id: I482cd1d2db310048de066aad33efbbe9c3f9e56a Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsvalue.cpp')
-rw-r--r--src/qml/jsapi/qjsvalue.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index c260ad2fa4..4b9a6e5a25 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -632,6 +632,8 @@ QVariant QJSValue::toVariant() const
\row \li Number \li A QVariant containing the value of the number.
\row \li String \li A QVariant containing the value of the string.
\row \li QVariant Object \li The result is the QVariant value of the object (no conversion).
+ \row \li QVariantMap Object \li A QVariant containing the QVariantMap stored in the object (no conversion).
+ \row \li QVariantHash Object \li A QVariant containing the QVariantHash stored in the object (no conversion).
\row \li QObject Object \li A QVariant containing a pointer to the QObject.
\row \li Date Object \li A QVariant containing the date value (toDateTime()).
\row \li RegularExpression Object \li A QVariant containing the regular expression value.
@@ -672,11 +674,6 @@ QVariant QJSValue::toVariant(QJSValue::ObjectConversionBehavior behavior) const
return QVariant(val.toQString());
if (behavior == RetainJSObjects) {
- // For historical reasons we don't want to retrieve the actual container here.
- // ### Qt7: change this
- if (val.as<QV4::VariantAssociationObject>())
- return QVariant::fromValue(QJSValuePrivate::fromReturnedValue(val.asReturnedValue()));
-
return QV4::ExecutionEngine::toVariant(
val, /*typeHint*/ QMetaType{}, /*createJSValueForObjectsAndSymbols=*/ true);
} else {