From d7ece941aebdac1be820fdfe74c273fb963dfcad Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 14 Sep 2018 11:11:32 -0400 Subject: Unwrap property updates in case they are QObjects When an object is initialized, QObject properties are properly unwrapped. However, before this patch, updates made to QObject properties were not unwrapped and thus could not be used from ECMAScript. For example, given a property defined as such: Q_PROPERTY(QObject* theProp READ theProp NOTIFY thePropChanged) The property "theProp" is correctly unwrapped when the parent object is created. However, it would not have been unwrapped when "thePropChanged" is emitted. This patch corrects that. Change-Id: If8f67560d9fb2a4bd909d2ab30305ceab30f8d31 Reviewed-by: Simon Hausmann Reviewed-by: Milian Wolff --- examples/webchannel/shared/qwebchannel.js | 2 +- tests/auto/qml/tst_webchannel.qml | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js index 9108a61..6cc3690 100644 --- a/examples/webchannel/shared/qwebchannel.js +++ b/examples/webchannel/shared/qwebchannel.js @@ -320,7 +320,7 @@ function QObject(name, data, webChannel) // update property cache for (var propertyIndex in propertyMap) { var propertyValue = propertyMap[propertyIndex]; - object.__propertyCache__[propertyIndex] = propertyValue; + object.__propertyCache__[propertyIndex] = this.unwrapQObject(propertyValue); } for (var signalName in signals) { diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml index 87ce84b..b0f3263 100644 --- a/tests/auto/qml/tst_webchannel.qml +++ b/tests/auto/qml/tst_webchannel.qml @@ -71,6 +71,9 @@ TestCase { lastFactoryObj = component.createObject(myFactory, {objectName: id}); return lastFactoryObj; } + function switchObject() { + otherObject = myOtherObj; + } property var objectInProperty: QtObject { objectName: "foo" } @@ -287,10 +290,6 @@ TestCase { client.awaitIdle(); - // trigger a signal and ensure it gets transmitted - lastFactoryObj.mySignal("foobar", 42); - client.awaitSignal(); - // property should be wrapped compare(channel.objects.myFactory.objectInProperty.objectName, "foo"); // list property as well @@ -303,6 +302,18 @@ TestCase { // also works with properties that reference other registered objects compare(channel.objects.myFactory.otherObject, channel.objects.myObj); + // change object property + channel.objects.myFactory.switchObject(); + client.awaitMessage(); + client.awaitResponse(); + client.awaitIdle(); + client.awaitPropertyUpdate(); + compare(channel.objects.myFactory.otherObject, channel.objects.myOtherObj); + + // trigger a signal and ensure it gets transmitted + lastFactoryObj.mySignal("foobar", 42); + client.awaitSignal(); + // deleteLater call msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod); -- cgit v1.2.1