From d82054df5d196016fafa4a0c5d4904ac6bde6364 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 18 Mar 2020 18:16:00 +0100 Subject: [PATCH] Fix param values getting lost in ScriptEvents --- libnymea-core/scriptengine/scriptevent.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libnymea-core/scriptengine/scriptevent.cpp b/libnymea-core/scriptengine/scriptevent.cpp index 87f3fa95..dd27d5cd 100644 --- a/libnymea-core/scriptengine/scriptevent.cpp +++ b/libnymea-core/scriptengine/scriptevent.cpp @@ -32,6 +32,7 @@ #include #include +#include namespace nymeaserver { @@ -104,16 +105,15 @@ void ScriptEvent::onEventTriggered(const Event &event) return; } -// ScriptParams *params = new ScriptParams(event.params()); -// qmlEngine(this)->setObjectOwnership(params, QQmlEngine::JavaScriptOwnership); QVariantMap params; foreach (const Param ¶m, event.params()) { - params.insert(param.paramTypeId().toString().remove(QRegExp("[{}]")), param.value()); + params.insert(param.paramTypeId().toString().remove(QRegExp("[{}]")), param.value().toByteArray()); QString paramName = thing->thingClass().eventTypes().findById(event.eventTypeId()).paramTypes().findById(param.paramTypeId()).name(); - params.insert(paramName, param.value()); + params.insert(paramName, param.value().toByteArray()); } - emit triggered(params); + // Note: Explicitly convert the params to a Json document because auto-casting from QVariantMap to the JS engine might drop some values. + emit triggered(QJsonDocument::fromVariant(params).toVariant().toMap()); } }