Doc fix: disconnect with receiver also works for context objects
One could guess it by assuming that disconnecting for a destroyed receiver and disconnect() with given receiver use the same implementation, but without closely knowing the implementation a reader of the documentation can't know for sure. Also add a test to prove that what the new documentation says is really true. Also remove an unnecessary negation in the preceding sentence. Change-Id: I9d24442bb1a4646b89f969bad1a4d0e1eafa7534 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>bb10
parent
7451453154
commit
7406949858
|
|
@ -5009,8 +5009,9 @@ bool QObject::disconnect(const QMetaObject::Connection &connection)
|
|||
any signal. If not, only the specified signal is disconnected.
|
||||
|
||||
If \a receiver is \nullptr, it disconnects anything connected to \a
|
||||
signal. If not, slots in objects other than \a receiver are not
|
||||
disconnected.
|
||||
signal. If not, only slots in the specified receiver are disconnected.
|
||||
disconnect() with a non-null \a receiver also disconnects slot functions
|
||||
that were connected with \a receiver as their context object.
|
||||
|
||||
If \a method is \nullptr, it disconnects anything that is connected to \a
|
||||
receiver. If not, only slots named \a method will be disconnected,
|
||||
|
|
|
|||
|
|
@ -6054,13 +6054,41 @@ void tst_QObject::connectFunctorWithContext()
|
|||
connect(context, &QObject::destroyed, &obj, &SenderObject::signal1, Qt::QueuedConnection);
|
||||
context->deleteLater();
|
||||
|
||||
QCOMPARE(status, 1);
|
||||
obj.emitSignal1();
|
||||
QCOMPARE(status, 2);
|
||||
e.exec();
|
||||
QCOMPARE(status, 1);
|
||||
QCOMPARE(status, 2);
|
||||
|
||||
// Check disconnect with the context object as "receiver" argument, all signals
|
||||
context = new ContextObject;
|
||||
status = 1;
|
||||
connect(&obj, &SenderObject::signal1, context, SlotArgFunctor(&status));
|
||||
|
||||
obj.emitSignal1();
|
||||
QCOMPARE(status, 2);
|
||||
QObject::disconnect(&obj, nullptr, context, nullptr);
|
||||
obj.emitSignal1();
|
||||
QCOMPARE(status, 2);
|
||||
|
||||
delete context;
|
||||
|
||||
// Check disconnect with the context object as "receiver" argument, specific signal
|
||||
context = new ContextObject;
|
||||
status = 1;
|
||||
connect(&obj, &SenderObject::signal1, context, SlotArgFunctor(&status));
|
||||
|
||||
obj.emitSignal1();
|
||||
QCOMPARE(status, 2);
|
||||
QObject::disconnect(&obj, &SenderObject::signal1, context, nullptr);
|
||||
obj.emitSignal1();
|
||||
QCOMPARE(status, 2);
|
||||
|
||||
delete context;
|
||||
|
||||
// Check the sender arg is set correctly in the context
|
||||
context = new ContextObject;
|
||||
|
||||
status = 1;
|
||||
connect(&obj, &SenderObject::signal1, context,
|
||||
SlotArgFunctor(context, &obj, &status), Qt::QueuedConnection);
|
||||
|
||||
|
|
@ -6077,8 +6105,7 @@ void tst_QObject::connectFunctorWithContext()
|
|||
e.exec();
|
||||
QCOMPARE(status, 2);
|
||||
|
||||
// Free
|
||||
context->deleteLater();
|
||||
delete context;
|
||||
}
|
||||
|
||||
class StatusChanger : public QObject
|
||||
|
|
|
|||
Loading…
Reference in New Issue