summaryrefslogtreecommitdiff
path: root/src/webchannel
diff options
context:
space:
mode:
Diffstat (limited to 'src/webchannel')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp20
-rw-r--r--src/webchannel/webchannel.pro5
2 files changed, 24 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);
diff --git a/src/webchannel/webchannel.pro b/src/webchannel/webchannel.pro
index 0678346..36cd686 100644
--- a/src/webchannel/webchannel.pro
+++ b/src/webchannel/webchannel.pro
@@ -27,4 +27,9 @@ SOURCES += \
qwebsocketserver.cpp \
qwebchannelsocket.cpp
+qtHaveModule(qml) {
+ QT += qml
+ DEFINES += HAVE_QML=1
+}
+
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS