diff options
author | Andrew Webster <awebster@arcx.com> | 2019-07-24 13:17:06 -0400 |
---|---|---|
committer | Andrew Webster <awebster@arcx.com> | 2019-09-20 08:33:52 -0400 |
commit | e535b24adf28ad6f0a93b7ecb37fccbef3a5d016 (patch) | |
tree | ceee54039ace8d23027851a57cee8b67e8294d9f /examples | |
parent | 26fbc4038223f5571dd048c1d800458708b6972c (diff) | |
download | qtwebchannel-e535b24adf28ad6f0a93b7ecb37fccbef3a5d016.tar.gz |
Unwrap QObjects embedded inside arguments
This converts QObjects that are embedded inside ECMAScript objects
into the actual QObject that they represent.
For example, if an array of QObjects is passed as an argument to
a method, the method will received a QVariantList where the
items are QVariants of type QObjectStar.
Method:
void processObjects(const QVariantList &list);
Call from ECMAScript:
theObj.processObjects([qobj1, qobj2])
Prior to this patch, the method would have received a list
containing QVariantMaps with keys from the QObject EMCAScript wrapper
(e.g. __objectSignals__, __propertyCache__, etc.).
After this patch, it will receive a list containing QVariants with
QObject* inside.
QVariantMaps are converted to QObjects if they have a property
called "__QObject*__" set to true and an "id" property.
"__QObject*__" is the same identifier for retuned objects and is
now added in a toJSON method at the client.
Change-Id: I5cafcddb9df0141977a574aaed4ce7c3ea2d0767
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/webchannel/shared/qwebchannel.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js index fca45d9..37ac9eb 100644 --- a/examples/webchannel/shared/qwebchannel.js +++ b/examples/webchannel/shared/qwebchannel.js @@ -351,10 +351,6 @@ function QObject(name, data, webChannel) var argument = arguments[i]; if (typeof argument === "function") callback = argument; - else if (argument instanceof QObject && webChannel.objects[argument.__id__] !== undefined) - args.push({ - "id": argument.__id__ - }); else args.push(argument); } @@ -426,8 +422,6 @@ function QObject(name, data, webChannel) } object.__propertyCache__[propertyIndex] = value; var valueToSend = value; - if (valueToSend instanceof QObject && webChannel.objects[valueToSend.__id__] !== undefined) - valueToSend = { "id": valueToSend.__id__ }; webChannel.exec({ "type": QWebChannelMessageTypes.setProperty, "object": object.__id__, @@ -452,6 +446,14 @@ function QObject(name, data, webChannel) } } +QObject.prototype.toJSON = function() { + if (this.__id__ === undefined) return {}; + return { + id: this.__id__, + "__QObject*__": true + }; +}; + //required for use with nodejs if (typeof module === 'object') { module.exports = { |