diff options
author | Kai Dohmen <psykai1993@googlemail.com> | 2016-04-11 19:38:50 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2016-06-21 09:50:33 +0000 |
commit | f48e8c9711fbeb350ccf70f852ce3732844d4287 (patch) | |
tree | 43756259e8794b89801cdc2aa936840af92c5d98 /src/webchannel/qwebchannel.js | |
parent | 3be67a7799aa1960d459548a43ddf54044f80ec1 (diff) | |
download | qtwebchannel-f48e8c9711fbeb350ccf70f852ce3732844d4287.tar.gz |
Make passing objects from website to server possible
If you get an object from the server and want to pass it back to the
server via a function the id of the object is passed instead of the
whole json object. On the server side QMetaObjectPublisher::invokeMethod
now looks up the object in QMetaObjectPublisher::wrappedObjects by the
passed object-id.
Task-number: QTBUG-50075
Change-Id: Id0df2dfaa79bcba12ca48391ae7537ac1a086898
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'src/webchannel/qwebchannel.js')
-rw-r--r-- | src/webchannel/qwebchannel.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/webchannel/qwebchannel.js b/src/webchannel/qwebchannel.js index d8c28bc..148e70d 100644 --- a/src/webchannel/qwebchannel.js +++ b/src/webchannel/qwebchannel.js @@ -324,10 +324,15 @@ function QObject(name, data, webChannel) var args = []; var callback; for (var i = 0; i < arguments.length; ++i) { - if (typeof arguments[i] === "function") - callback = arguments[i]; + 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(arguments[i]); + args.push(argument); } webChannel.exec({ @@ -381,11 +386,14 @@ function QObject(name, data, webChannel) return; } 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__, "property": propertyIndex, - "value": value + "value": valueToSend }); } }); |