diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2017-04-20 12:05:11 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2017-05-15 14:37:49 +0000 |
commit | 446978af11ab886d734ca3972dcd73f847df9fbc (patch) | |
tree | 3d002cb799aa73aad0c93929b083903c66a48e7c | |
parent | 36a42a2ebd3198654a29afe7f6bb450849c745ea (diff) | |
download | qtwebchannel-446978af11ab886d734ca3972dcd73f847df9fbc.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: I7abad204cbab72be7729d42f58ce63babd2310d8
Task-number: QTBUG-60250
Reviewed-by: Kai Dohmen <psykai1993@googlemail.com>
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
-rw-r--r-- | src/webchannel/qmetaobjectpublisher.cpp | 8 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 15 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.h | 1 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index 148404d..dcc589c 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -454,8 +454,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 24d473f..2e80477 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -312,6 +312,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 5e832c9..aaacb5a 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -285,6 +285,7 @@ signals: private slots: void testRegisterObjects(); void testDeregisterObjects(); + void testDeregisterObjectAtStart(); void testInfoForObject(); void testInvokeMethodConversion(); void testSetPropertyConversion(); |