From 81dac6e848da8e8a071a2069862590889a287067 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 16 Oct 2014 13:37:22 +0200 Subject: Make objects inside properties accessible. Similar to the support for factory-methods, we must wrap objects in properties to make them accessible to clients. This patch adds the required code for that. Besides support for simple properties that reference an object, this patch also adds support for list properties that contain objects. The client-side unwrap of properties is delayed until all objects are initialized, as a property might reference another registered object. Change-Id: I9fb90a8eab4c66d2f4231fdb482e0d97d128df3e Reviewed-by: Milian Wolff --- tests/auto/qml/tst_webchannel.qml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml index f304197..e7fcedc 100644 --- a/tests/auto/qml/tst_webchannel.qml +++ b/tests/auto/qml/tst_webchannel.qml @@ -66,6 +66,8 @@ TestCase { property var bar: 1 WebChannel.id: "myOtherObj" } + QtObject{ id: bar; objectName: "bar" } + QtObject{ id: baz; objectName: "baz" } QtObject { id: myFactory property var lastObj @@ -74,9 +76,13 @@ TestCase { lastObj = component.createObject(myFactory, {objectName: id}); return lastObj; } + property var objectInProperty: QtObject { + objectName: "foo" + } + property var otherObject: myObj + property var objects: [ bar, baz ]; WebChannel.id: "myFactory" } - Component { id: component QtObject { @@ -264,6 +270,15 @@ TestCase { myFactory.lastObj.mySignal("foobar", 42); + // property should be wrapped + compare(channel.objects.myFactory.objectInProperty.objectName, "foo"); + // list property as well + compare(channel.objects.myFactory.objects.length, 2); + compare(channel.objects.myFactory.objects[0].objectName, "bar"); + compare(channel.objects.myFactory.objects[1].objectName, "baz"); + // also works with properties that reference other registered objects + compare(channel.objects.myFactory.otherObject, channel.objects.myObj); + // deleteLater call msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod); -- cgit v1.2.1 From ed40ffb381e1f874145b70de43961298428c03af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lutz=20Sch=C3=B6nemann?= Date: Mon, 1 Dec 2014 16:12:22 +0100 Subject: Fix crash on signal after deregistration Implemented a remove method in SignalHandler that allows us to remove and disconnect an object from SignalHandler w/o decrementing the connection counter until it hits zero or deleting the object That same functionality was used to remove an object from internal lists when receiving a destroyed signal from an object. In case of deregistering an object we haven't received a destoryed signal but simulated reception of that signal and so that code was not called in that case. Change-Id: Ie20cf628a2de028375f5d29f913682e25ebf8d44 Reviewed-by: Milian Wolff --- tests/auto/webchannel/tst_webchannel.cpp | 24 ++++++++++++++++++++++++ tests/auto/webchannel/tst_webchannel.h | 1 + 2 files changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 4827ea7..3304293 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -83,6 +83,30 @@ void TestWebChannel::testRegisterObjects() channel.registerObjects(objects); } +void TestWebChannel::testDeregisterObjects() +{ + QWebChannel channel; + TestObject testObject; + testObject.setObjectName("myTestObject"); + + + channel.registerObject(testObject.objectName(), &testObject); + + channel.connectTo(m_dummyTransport); + channel.d_func()->publisher->initializeClients(); + + QJsonObject connectMessage = + QJsonDocument::fromJson(("{\"type\": 7," + "\"object\": \"myTestObject\"," + "\"signal\": " + QString::number(testObject.metaObject()->indexOfSignal("sig1()")) + + "}").toLatin1()).object(); + channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport); + + emit testObject.sig1(); + channel.deregisterObject(&testObject); + emit testObject.sig1(); +} + void TestWebChannel::testInfoForObject() { TestObject obj; diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index ad8c6a4..6564944 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -214,6 +214,7 @@ public: private slots: void testRegisterObjects(); + void testDeregisterObjects(); void testInfoForObject(); void testInvokeMethodConversion(); void testDisconnect(); -- cgit v1.2.1