diff options
author | Andrew Webster <awebster@arcx.com> | 2018-09-13 16:59:44 -0400 |
---|---|---|
committer | Andrew Webster <awebster@arcx.com> | 2019-02-06 18:56:35 +0000 |
commit | e283b0852c25dba2ef73556062b5605af3632b05 (patch) | |
tree | f14e5452047291e8e4dd1656f33d654db9fe8c9c /examples | |
parent | 93db9349c3f40fad6e4a7d94a719dcbeb1195590 (diff) | |
download | qtwebchannel-e283b0852c25dba2ef73556062b5605af3632b05.tar.gz |
Convert QObjects in QVariantMaps
QObjects that are present in an array are already converted to
an object identifier. This does the same for variant maps, which
end up as ECMAScript objects.
This allows QObjects put into a QVariantMap to be properly
deserialized. For example, if a property is declared as such:
Q_PROPERTY(QVariantMap propName READ propName CONSTANT)
And propName is:
QVariantMap propName() const {
QVariantMap map;
map.insert("theProperty", QVariant::fromValue(someQObject));
return map;
}
The "theProperty" property will now properly refer to the object.
Change-Id: I3c6e71b860f6825a31eb337aeffa55302287c8ff
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/webchannel/shared/qwebchannel.js | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js index 5b047c2..d75e148 100644 --- a/examples/webchannel/shared/qwebchannel.js +++ b/examples/webchannel/shared/qwebchannel.js @@ -197,10 +197,16 @@ function QObject(name, data, webChannel) } return ret; } - if (!response - || !response["__QObject*__"] - || response.id === undefined) { + if (!(response instanceof Object)) return response; + + if (!response["__QObject*__"] + || response.id === undefined) { + var jObj = {}; + for (var propName in response) { + jObj[propName] = object.unwrapQObject(response[propName]); + } + return jObj; } var objectId = response.id; |