summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2019-12-13 16:38:59 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-04-15 15:57:41 +0200
commitbdec52548ca739e5533792c3bf656b8e2cf9fcb6 (patch)
treebbec422c569f18ba9f4b898c2fe392c07360f0a2 /src
parent1f793c887773f9b7477a73467aa1e2497ffef25c (diff)
downloadqtwebchannel-bdec52548ca739e5533792c3bf656b8e2cf9fcb6.tar.gz
Restore compatibility with custom QVariantList/QVariantMap converters
QVariant::toValue<QVariantList> does not honor explicit custom converters for a sequentially iterable container to a QVariantList. This breaks compatibility with Qt 5.12.3 and before, where the old code path using QVariant::toList() used the custom converter. Do the same for QVariantMap. This patch restores the compatibility with old code. The real fix will target the QVariantList converter code in QtCore - this is just a hotfix within Qt WebChannel for now. Task-number: QTBUG-80751 Change-Id: Ic70c6a353aad43ddbaefbc6626a0af87bd0d024f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index e23921d..ea7ddc9 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -788,10 +788,19 @@ QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result, QWebChannelA
// *don't* use result.toList() as that *only* works for QVariantList and QStringList!
// Also, don't use QSequentialIterable (yet), since that seems to trigger QTBUG-42016
// in certain cases.
- return wrapList(result.value<QVariantList>(), transport);
+ // additionally, when there's a direct converter to QVariantList, use that one via convert
+ // but recover when conversion fails and fall back to the .value<QVariantList> conversion
+ // see also: https://bugreports.qt.io/browse/QTBUG-80751
+ auto list = result;
+ if (!list.convert(qMetaTypeId<QVariantList>()))
+ list = result;
+ return wrapList(list.value<QVariantList>(), transport);
} else if (result.canConvert<QVariantMap>()) {
// recurse and potentially wrap contents of the map
- return wrapMap(result.toMap(), transport);
+ auto map = result;
+ if (!map.convert(qMetaTypeId<QVariantMap>()))
+ map = result;
+ return wrapMap(map.value<QVariantMap>(), transport);
}
return QJsonValue::fromVariant(result);