summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qobject.cpp5
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp35
2 files changed, 34 insertions, 6 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 62bee3d90b..b749e3916c 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -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,
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index c84c812823..1d274d8c95 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -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