diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-05-14 21:06:39 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-05-14 21:06:39 +0200 |
commit | 2398037151babcb817c94463fc240c7694f73d4c (patch) | |
tree | 7ba502f85a57a3aedceb893f379e6a5436f680e7 | |
parent | 8554d71f47f85b111f095ea8f25c3a72c5cae32e (diff) | |
parent | 3342da908955187a4543cdc38e0fad2e78e936e7 (diff) | |
download | qtwebchannel-2398037151babcb817c94463fc240c7694f73d4c.tar.gz |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I6417958acf66455b993c65f51b58f15955aa95f4
-rw-r--r-- | dist/changes-5.14.2 | 20 | ||||
-rw-r--r-- | dist/changes-5.15.0 | 18 | ||||
-rw-r--r-- | src/webchannel/qmetaobjectpublisher.cpp | 13 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 41 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.h | 13 |
5 files changed, 97 insertions, 8 deletions
diff --git a/dist/changes-5.14.2 b/dist/changes-5.14.2 new file mode 100644 index 0000000..68a0051 --- /dev/null +++ b/dist/changes-5.14.2 @@ -0,0 +1,20 @@ +Qt 5.14.2 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.14.0 through 5.14.1. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.14 series is binary compatible with the 5.13.x series. +Applications compiled for 5.13 will continue to run with 5.14. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/dist/changes-5.15.0 b/dist/changes-5.15.0 new file mode 100644 index 0000000..40076ce --- /dev/null +++ b/dist/changes-5.15.0 @@ -0,0 +1,18 @@ +Qt 5.15 introduces many new features and improvements as well as bugfixes +over the 5.14.x series. For more details, refer to the online documentation +included in this distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.15 series is binary compatible with the 5.14.x series. +Applications compiled for 5.14 will continue to run with 5.15. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index c0a12dc..f6110ed 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -827,10 +827,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); 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 |