summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Webster <awebster@arcx.com>2018-09-14 11:11:32 -0400
committerMilian Wolff <milian.wolff@kdab.com>2019-04-10 08:53:47 +0000
commitd7ece941aebdac1be820fdfe74c273fb963dfcad (patch)
tree06ea43e8505e22090bab22af588f33a5bf4ab0ce
parentb1908a1f8fa7cd358e830ba774b92452fc7085f9 (diff)
downloadqtwebchannel-d7ece941aebdac1be820fdfe74c273fb963dfcad.tar.gz
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 <simon.hausmann@qt.io> Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
-rw-r--r--examples/webchannel/shared/qwebchannel.js2
-rw-r--r--tests/auto/qml/tst_webchannel.qml19
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);