summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-08-26 17:18:40 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-08-27 15:45:25 +0200
commit7d4d47de7049ba52726071d4d2ba03fc014aa48d (patch)
tree2f97c146dd7b27febc4acdb6944f2dfdffa08b6b /tests
parentc9830c2fb902f26dc8b2df61dfadc2d7a7d2b30e (diff)
QObject::connect(): fail to connect to a functor if UniqueConnection is passed
The connect() documentation makes it clear that UniqueConnection does not work with free functions / function objects and the like; only with actual PMFs. Rather than silently *ignoring* the flag, be vocal about its presence by warning, and make the connection fail (as the user has passed an illegal argument). [ChangeLog][QtCore][QObject] QObject::connect() now will refuse to connect a signal to a free function / function object if UniqueConnection is passed. Note that UniqueConnection has never worked for such connections -- the flag was simply ignored, and they were established multiple times. Now, the flag is not ignored and results in a connection failure (as well as a runtime warning by Qt). Change-Id: I6509667018c74f9bd24910cde0a1b16c5f84f064 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 599f690ab2..52b687cbfa 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -6241,10 +6241,11 @@ void tst_QObject::connectFunctorWithContextUnique()
SenderObject sender;
ReceiverObject receiver;
- QObject::connect(&sender, &SenderObject::signal1, &receiver, &ReceiverObject::slot1);
+ QVERIFY(QObject::connect(&sender, &SenderObject::signal1, &receiver, &ReceiverObject::slot1));
receiver.count_slot1 = 0;
- QObject::connect(&sender, &SenderObject::signal1, &receiver, SlotFunctor(), Qt::UniqueConnection);
+ QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): unique connections require a pointer to member function of a QObject subclass");
+ QVERIFY(!QObject::connect(&sender, &SenderObject::signal1, &receiver, [&](){ receiver.slot1(); }, Qt::UniqueConnection));
sender.emitSignal1();
QCOMPARE(receiver.count_slot1, 1);