summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2017-04-20 12:05:11 +0200
committerMilian Wolff <milian.wolff@kdab.com>2017-06-26 13:25:40 +0000
commit64306392ce3a7751bfb58e1352b212ad5cba8aec (patch)
tree966c77986bf46dc0a402b3327e24f7803afefa37
parent18a53cef73eed59cddd7962d4e4aa8fbf7d3170a (diff)
downloadqtwebchannel-64306392ce3a7751bfb58e1352b212ad5cba8aec.tar.gz
Gracefully handle early deregistration of objects
When an object is deregistered before the signal handler got initializated, we asserted. Now, we check for this case and skip the signal handler removal when it wasn't set up yet. Change-Id: I1edb5fb4f1429e6c69c6c41baabd3d30a4b6fe10 Task-number: QTBUG-60250 Reviewed-by: Kai Dohmen <psykai1993@googlemail.com> Reviewed-by: Konstantin Tokarev <annulen@yandex.ru> (cherry picked from commit 446978af11ab886d734ca3972dcd73f847df9fbc)
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp8
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp15
-rw-r--r--tests/auto/webchannel/tst_webchannel.h1
3 files changed, 22 insertions, 2 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index 85a9b35..8fc54a4 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -448,8 +448,12 @@ void QMetaObjectPublisher::objectDestroyed(const QObject *object)
Q_ASSERT(removed);
Q_UNUSED(removed);
- signalHandler.remove(object);
- signalToPropertyMap.remove(object);
+ // only remove from handler when we initialized the property updates
+ // cf: https://bugreports.qt.io/browse/QTBUG-60250
+ if (propertyUpdatesInitialized) {
+ signalHandler.remove(object);
+ signalToPropertyMap.remove(object);
+ }
pendingPropertyUpdates.remove(object);
}
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index 2ab820b..95a6160 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -317,6 +317,21 @@ void TestWebChannel::testDeregisterObjects()
emit testObject.sig1();
}
+void TestWebChannel::testDeregisterObjectAtStart()
+{
+ QWebChannel channel;
+ QVERIFY(channel.registeredObjects().isEmpty());
+
+ TestObject testObject;
+ testObject.setObjectName("myTestObject");
+
+ channel.registerObject(testObject.objectName(), &testObject);
+ QCOMPARE(channel.registeredObjects().size(), 1);
+
+ channel.deregisterObject(&testObject);
+ QVERIFY(channel.registeredObjects().isEmpty());
+}
+
void TestWebChannel::testInfoForObject()
{
TestObject obj;
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index 94dccf5..1f36fbe 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -290,6 +290,7 @@ signals:
private slots:
void testRegisterObjects();
void testDeregisterObjects();
+ void testDeregisterObjectAtStart();
void testInfoForObject();
void testInvokeMethodConversion();
void testSetPropertyConversion();