summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2011-11-18 10:57:04 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-29 17:08:39 +0100
commited0b262de97dd92c831127909ea4c059962b86ce (patch)
treeb5ab25866220b0d0a136bd5b77dd227d55fcb0f8 /tests/auto/corelib/kernel/qobject/tst_qobject.cpp
parenta482487b9ff0cf0c47f9c0927c44019d52e2fdf8 (diff)
QObject::disconnect with new syntax
This add an overload to disconnect which is symetrical to the new syntax of connect. It is possible to diconnect connection like this: QObject::connect( sender, &Sender::valueChanged, receiver, &Receiver::updateValue ); QObject::disconnect( sender, &Sender::valueChanged, receiver, &Receiver::updateValue ); This overload only work with pointer to member function, and not static functions or functors. The test is copied from tst_QObject::disconnect(), just changed the syntax of the connection and disconnection Change-Id: Ia8f819100cb12098e32877522b97b732b1e676a8 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 77e9a9e42d..f5d06d27ee 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -122,6 +122,7 @@ private slots:
void autoConnectionBehavior();
void baseDestroyed();
void pointerConnect();
+ void pointerDisconnect();
void emitInDefinedOrderPointer();
void customTypesPointer();
void connectCxx0x();
@@ -4104,6 +4105,110 @@ void tst_QObject::pointerConnect()
delete r2;
}
+void tst_QObject::pointerDisconnect()
+{
+ SenderObject *s = new SenderObject;
+ ReceiverObject *r1 = new ReceiverObject;
+ ReceiverObject *r2 = new ReceiverObject;
+
+ connect( s, &SenderObject::signal1, r1, &ReceiverObject::slot1 );
+
+ connect( s, &SenderObject::signal2, r1, &ReceiverObject::slot2 );
+ connect( s, &SenderObject::signal3, r1, &ReceiverObject::slot3 );
+ connect( s, &SenderObject::signal4, r1, &ReceiverObject::slot4 );
+
+ s->emitSignal1();
+ s->emitSignal2();
+ s->emitSignal3();
+ s->emitSignal4();
+
+ QCOMPARE( r1->called(1), TRUE );
+ QCOMPARE( r1->called(2), TRUE );
+ QCOMPARE( r1->called(3), TRUE );
+ QCOMPARE( r1->called(4), TRUE );
+ r1->reset();
+
+ // usual disconnect with all parameters given
+ bool ret = QObject::disconnect( s, &SenderObject::signal1, r1, &ReceiverObject::slot1 );
+
+ s->emitSignal1();
+
+ QCOMPARE( r1->called(1), FALSE );
+ r1->reset();
+
+ QCOMPARE( ret, TRUE );
+ ret = QObject::disconnect( s, &SenderObject::signal1, r1, &ReceiverObject::slot1 );
+ QCOMPARE( ret, FALSE );
+
+ // disconnect all signals from s from all slots from r1
+ QObject::disconnect( s, 0, r1, 0 );
+
+ s->emitSignal2();
+ s->emitSignal3();
+ s->emitSignal4();
+
+ QCOMPARE( r1->called(2), FALSE );
+ QCOMPARE( r1->called(3), FALSE );
+ QCOMPARE( r1->called(4), FALSE );
+ r1->reset();
+
+ connect( s, &SenderObject::signal1, r1, &ReceiverObject::slot1 );
+ connect( s, &SenderObject::signal1, r1, &ReceiverObject::slot2 );
+ connect( s, &SenderObject::signal1, r1, &ReceiverObject::slot3 );
+ connect( s, &SenderObject::signal2, r1, &ReceiverObject::slot4 );
+
+ // disconnect s's signal1() from all slots of r1
+ QObject::disconnect( s, &SenderObject::signal1, r1, 0 );
+
+ s->emitSignal1();
+ s->emitSignal2();
+
+ QCOMPARE( r1->called(1), FALSE );
+ QCOMPARE( r1->called(2), FALSE );
+ QCOMPARE( r1->called(3), FALSE );
+ QCOMPARE( r1->called(4), TRUE );
+ r1->reset();
+ // make sure all is disconnected again
+ QObject::disconnect( s, 0, r1, 0 );
+
+ connect( s, &SenderObject::signal1, r1, &ReceiverObject::slot1 );
+ connect( s, &SenderObject::signal1, r2, &ReceiverObject::slot1 );
+ connect( s, &SenderObject::signal2, r1, &ReceiverObject::slot2 );
+ connect( s, &SenderObject::signal2, r2, &ReceiverObject::slot2 );
+ connect( s, &SenderObject::signal3, r1, &ReceiverObject::slot3 );
+ connect( s, &SenderObject::signal3, r2, &ReceiverObject::slot3 );
+
+ // disconnect signal1() from all receivers
+ QObject::disconnect( s, &SenderObject::signal1, 0, 0 );
+ s->emitSignal1();
+ s->emitSignal2();
+ s->emitSignal3();
+
+ QCOMPARE( r1->called(1), FALSE );
+ QCOMPARE( r2->called(1), FALSE );
+ QCOMPARE( r1->called(2), TRUE );
+ QCOMPARE( r2->called(2), TRUE );
+ QCOMPARE( r1->called(2), TRUE );
+ QCOMPARE( r2->called(2), TRUE );
+
+ r1->reset();
+ r2->reset();
+
+ // disconnect all signals of s from all receivers
+ QObject::disconnect( s, 0, 0, 0 );
+
+ QCOMPARE( r1->called(2), FALSE );
+ QCOMPARE( r2->called(2), FALSE );
+ QCOMPARE( r1->called(2), FALSE );
+ QCOMPARE( r2->called(2), FALSE );
+
+ delete r2;
+ delete r1;
+ delete s;
+
+}
+
+
void tst_QObject::emitInDefinedOrderPointer()
{
SenderObject sender;