Fix QObject::receivers() within connectNotify()
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>
Fri, 28 Sep 2012 09:28:23 +0000 (11:28 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 10 Oct 2012 09:21:15 +0000 (11:21 +0200)
The receiver count needs to be correct in connectNotify() to be
compatible with ordinary connections.
Fix this and add test.

Change-Id: Icff0486dac49876b8c5d8836a85cff9284368a52
Reviewed-by: Alan Alpert <416365416c@gmail.com>
src/qml/qml/qqmlnotifier_p.h
tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp

index 4bf8015..e3c2271 100644 (file)
@@ -189,13 +189,17 @@ void QQmlNotifierEndpoint::connect(QQmlNotifier *notifier)
 
 void QQmlNotifierEndpoint::disconnect()
 {
+    // Remove from notifier chain before calling disconnectNotify(), so that that
+    // QObject::receivers() returns the correct value in there
+    if (next) next->prev = prev;
+    if (prev) *prev = next;
+
     if (sourceSignal != -1) {
         QObject * const obj = senderAsObject();
         QObjectPrivate * const priv = QObjectPrivate::get(obj);
         priv->disconnectNotify(QMetaObjectPrivate::signal(obj->metaObject(), sourceSignal));
     }
-    if (next) next->prev = prev;
-    if (prev) *prev = next;
+
     if (isNotifying()) *((intptr_t *)(senderPtr & ~0x1)) = 0;
     next = 0;
     prev = 0;
index fdfa211..ae37b6a 100644 (file)
@@ -120,6 +120,7 @@ protected:
         if (signal.name() == "scriptBindingPropChanged") scriptBindingPropConnections++;
         if (signal.name() == "boundSignal")   boundSignalConnections++;
         if (signal.name() == "unusedSignal") unusedSignalConnections++;
+        verifyReceiverCount();
         //qDebug() << Q_FUNC_INFO << this << signal.name();
     }
 
@@ -133,6 +134,7 @@ protected:
         if (signal.name() == "scriptBindingPropChanged") scriptBindingPropConnections--;
         if (signal.name() == "boundSignal")   boundSignalConnections--;
         if (signal.name() == "unusedSignal") unusedSignalConnections--;
+        verifyReceiverCount();
         //qDebug() << Q_FUNC_INFO << this << signal.methodSignature();
     }