From bdec52548ca739e5533792c3bf656b8e2cf9fcb6 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 13 Dec 2019 16:38:59 +0100 Subject: Restore compatibility with custom QVariantList/QVariantMap converters QVariant::toValue 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 --- src/webchannel/qmetaobjectpublisher.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') 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(), 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 conversion + // see also: https://bugreports.qt.io/browse/QTBUG-80751 + auto list = result; + if (!list.convert(qMetaTypeId())) + list = result; + return wrapList(list.value(), transport); } else if (result.canConvert()) { // recurse and potentially wrap contents of the map - return wrapMap(result.toMap(), transport); + auto map = result; + if (!map.convert(qMetaTypeId())) + map = result; + return wrapMap(map.value(), transport); } return QJsonValue::fromVariant(result); -- cgit v1.2.1 From 4af709df207bf7c98ae5ffd699a66d33767d6300 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 15 Apr 2020 15:51:11 +0200 Subject: Fix deprecation warning Change-Id: Ieb3f0ef5e5b752613d664731e250dba14fb42f0a Reviewed-by: Milian Wolff --- src/webchannel/qmetaobjectpublisher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index ea7ddc9..677f79c 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -869,7 +869,7 @@ void QMetaObjectPublisher::handleMessage(const QJsonObject &message, QWebChannel transport->sendMessage(createResponse(message.value(KEY_ID), initializeClient(transport))); } else if (type == TypeDebug) { static QTextStream out(stdout); - out << "DEBUG: " << message.value(KEY_DATA).toString() << endl; + out << "DEBUG: " << message.value(KEY_DATA).toString() << Qt::endl; } else if (message.contains(KEY_OBJECT)) { const QString &objectName = message.value(KEY_OBJECT).toString(); QObject *object = registeredObjects.value(objectName); -- cgit v1.2.1