Call disconnectNotify() when disconnecting a QMetaObject::Connection
In all other forms of disconnecting this is done. We also know the signal index, so there is no reason not to do this. Change-Id: Ic8b042cd8f45dbff74b42ee30c384a84bef78b20 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
ff11c363b1
commit
972580accd
@ -4776,11 +4776,12 @@ bool QObject::disconnect(const QMetaObject::Connection &connection)
|
||||
c->isSlotObject = false;
|
||||
}
|
||||
|
||||
c->sender->disconnectNotify(QMetaObjectPrivate::signal(c->sender->metaObject(),
|
||||
c->signal_index));
|
||||
|
||||
const_cast<QMetaObject::Connection &>(connection).d_ptr = 0;
|
||||
c->deref(); // has been removed from the QMetaObject::Connection object
|
||||
|
||||
// disconnectNotify() not called (the signal index is unknown).
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ private slots:
|
||||
void connectDisconnectNotify();
|
||||
void connectDisconnectNotifyPMF();
|
||||
void disconnectNotify_receiverDestroyed();
|
||||
void disconnectNotify_metaObjConnection();
|
||||
void connectNotify_connectSlotsByName();
|
||||
void connectDisconnectNotify_shadowing();
|
||||
void emitInDefinedOrder();
|
||||
@ -923,8 +924,7 @@ void tst_QObject::connectDisconnectNotifyPMF()
|
||||
|
||||
// Test disconnectNotify when disconnecting by QMetaObject::Connection
|
||||
QVERIFY(QObject::disconnect(conn));
|
||||
// disconnectNotify() is not called, but it probably should be.
|
||||
QVERIFY(s->disconnectedSignals.isEmpty());
|
||||
QVERIFY(!s->disconnectedSignals.isEmpty());
|
||||
|
||||
// Test connectNotify when connecting by function pointer
|
||||
s->clearNotifications();
|
||||
@ -969,6 +969,25 @@ void tst_QObject::disconnectNotify_receiverDestroyed()
|
||||
delete s;
|
||||
}
|
||||
|
||||
void tst_QObject::disconnectNotify_metaObjConnection()
|
||||
{
|
||||
NotifyObject *s = new NotifyObject;
|
||||
NotifyObject *r = new NotifyObject;
|
||||
|
||||
QMetaObject::Connection c = QObject::connect((SenderObject*)s, SIGNAL(signal1()),
|
||||
(ReceiverObject*)r, SLOT(slot1()));
|
||||
QVERIFY(c);
|
||||
QVERIFY(QObject::disconnect(c));
|
||||
|
||||
QCOMPARE(s->disconnectedSignals.count(), 1);
|
||||
QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&SenderObject::signal1));
|
||||
|
||||
delete r;
|
||||
QCOMPARE(s->disconnectedSignals.count(), 1);
|
||||
|
||||
delete s;
|
||||
}
|
||||
|
||||
class ConnectByNameNotifySenderObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
Reference in New Issue
Block a user