summaryrefslogtreecommitdiff
path: root/src/webchannel/qmetaobjectpublisher.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-01-08 17:59:55 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-09 13:35:45 +0100
commit3ae3b765fcc650d34c5f777e39b2302b77896d04 (patch)
tree98e0b7bc2845a6710d643ede1ea1fde7ff671ab8 /src/webchannel/qmetaobjectpublisher.cpp
parent4117c5b8ea09d1ed872927edb31a63868c3f43e2 (diff)
downloadqtwebchannel-3ae3b765fcc650d34c5f777e39b2302b77896d04.tar.gz
Fix regression in handling of var-emitting signals from QML.
Qt 5.3 propagates var-arguments of signals as QJSValue instead of as a QVariant. This then fails to be serialized to QJson, failing our unit tests. Now, QJSValue types are manually casted to QJsonValues which makes the tests pass again. Change-Id: I730c595eee214ebe3d1f83009cd5605f66407f55 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher.cpp')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index d3659bd..2f0ef74 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -49,6 +49,11 @@
#include <QJsonObject>
#include <QJsonArray>
+#if HAVE_QML
+#include <QtQml/QJSValue>
+#include <QtQml/QJSEngine>
+#endif
+
namespace {
const QString KEY_SIGNALS = QStringLiteral("signals");
const QString KEY_METHODS = QStringLiteral("methods");
@@ -375,7 +380,20 @@ void QMetaObjectPublisher::signalEmitted(const QObject *object, const int signal
data[KEY_SIGNAL] = signalIndex;
if (!arguments.isEmpty()) {
// TODO: wrap (new) objects on the fly
- data[KEY_ARGS] = QJsonArray::fromVariantList(arguments);
+ QJsonArray args;
+#if HAVE_QML
+ foreach (const QVariant &arg, arguments) {
+ if (arg.canConvert<QJSValue>()) {
+ const QJSValue &jsValue = arg.value<QJSValue>();
+ args.append(qjsvalue_cast<QJsonValue>(jsValue));
+ } else {
+ args.append(QJsonValue::fromVariant(arg));
+ }
+ }
+#else
+ args = QJsonArray::fromVariantList(arguments);
+#endif
+ data[KEY_ARGS] = args;
}
webChannel->sendMessage(TYPE_SIGNAL, data);