aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--src/imports/webchannel/plugins.qmltypes2
-rw-r--r--src/webchannel/doc/src/javascript.qdoc4
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp15
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp41
-rw-r--r--tests/auto/webchannel/tst_webchannel.h13
6 files changed, 64 insertions, 13 deletions
diff --git a/.qmake.conf b/.qmake.conf
index a22e93e..748ca99 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,4 +1,4 @@
load(qt_build_config)
CONFIG += warning_clean
-MODULE_VERSION = 5.14.2
+MODULE_VERSION = 5.15.0
diff --git a/src/imports/webchannel/plugins.qmltypes b/src/imports/webchannel/plugins.qmltypes
index 278e787..68378d6 100644
--- a/src/imports/webchannel/plugins.qmltypes
+++ b/src/imports/webchannel/plugins.qmltypes
@@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtWebChannel 1.14'
+// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtWebChannel 1.15'
Module {
dependencies: []
diff --git a/src/webchannel/doc/src/javascript.qdoc b/src/webchannel/doc/src/javascript.qdoc
index ef44250..92170a0 100644
--- a/src/webchannel/doc/src/javascript.qdoc
+++ b/src/webchannel/doc/src/javascript.qdoc
@@ -89,8 +89,8 @@ new QWebChannel(yourTransport, function(channel) {
// To get notified about remote property changes,
// simply connect to the corresponding notify signal:
- foo.onMyPropertyChanged.connect(function(newValue) {
- console.log(newValue);
+ foo.myPropertyChanged.connect(function() {
+ console.log(foo.myProperty);
});
// One can also access enums that are marked with Q_ENUM:
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index e23921d..677f79c 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);
@@ -860,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);
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index c47cd6b..a1e824b 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -183,6 +183,20 @@ void TestJSEngine::initWebChannelJS()
#endif // WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE
+namespace {
+QVariantList convert_to_js(const TestStructVector &list)
+{
+ QVariantList ret;
+ ret.reserve(list.size());
+ std::transform(list.begin(), list.end(), std::back_inserter(ret), [](const TestStruct &value) -> QVariant {
+ QVariantMap map;
+ map["foo"] = value.foo;
+ map["bar"] = value.bar;
+ return map;
+ });
+ return ret;
+}
+}
TestWebChannel::TestWebChannel(QObject *parent)
: QObject(parent)
@@ -191,6 +205,9 @@ TestWebChannel::TestWebChannel(QObject *parent)
, m_lastBool(false)
, m_lastDouble(0)
{
+ qRegisterMetaType<TestStruct>();
+ qRegisterMetaType<TestStructVector>();
+ QMetaType::registerConverter<TestStructVector, QVariantList>(convert_to_js);
}
TestWebChannel::~TestWebChannel()
@@ -864,6 +881,14 @@ void TestWebChannel::testWrapValues()
QVERIFY(value.isArray());
QCOMPARE(value.toArray(), QJsonArray({1, 2, 3}));
}
+ {
+ TestStructVector vec{{1, 2}, {3, 4}};
+ QVariant variant = QVariant::fromValue(vec);
+ QJsonValue value = channel.d_func()->publisher->wrapResult(variant, m_dummyTransport);
+ QVERIFY(value.isArray());
+ QCOMPARE(value.toArray(), QJsonArray({QJsonObject{{"foo", 1}, {"bar", 2}},
+ QJsonObject{{"foo", 3}, {"bar", 4}}}));
+ }
}
void TestWebChannel::testWrapObjectWithMultipleTransports()
@@ -930,10 +955,13 @@ void TestWebChannel::testAsyncObject()
args.append(QJsonValue("message"));
{
- QSignalSpy spy(&obj, &TestObject::propChanged);
+ int received = 0;
+ connect(&obj, &TestObject::propChanged, this, [&](const QString &arg) {
+ QCOMPARE(arg, args.at(0).toString());
+ ++received;
+ });
channel.d_func()->publisher->invokeMethod(&obj, "setProp", args);
- QTRY_COMPARE(spy.count(), 1);
- QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString());
+ QTRY_COMPARE(received, 1);
}
channel.registerObject("myObj", &obj);
@@ -946,12 +974,13 @@ void TestWebChannel::testAsyncObject()
channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport);
{
- QSignalSpy spy(&obj, &TestObject::replay);
+ int received = 0;
+ connect(&obj, &TestObject::replay, this, [&]() { ++received; });
QMetaObject::invokeMethod(&obj, "fire");
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(received, 1);
channel.deregisterObject(&obj);
QMetaObject::invokeMethod(&obj, "fire");
- QTRY_COMPARE(spy.count(), 2);
+ QTRY_COMPARE(received, 2);
}
thread.quit();
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index 7cfce06..eae21f4 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -39,6 +39,19 @@
#include <QtWebChannel/QWebChannelAbstractTransport>
+struct TestStruct
+{
+ TestStruct(int foo = 0, int bar = 0)
+ : foo(foo)
+ , bar(bar)
+ {}
+ int foo;
+ int bar;
+};
+Q_DECLARE_METATYPE(TestStruct)
+using TestStructVector = std::vector<TestStruct>;
+Q_DECLARE_METATYPE(TestStructVector)
+
QT_BEGIN_NAMESPACE
class DummyTransport : public QWebChannelAbstractTransport