Fix crash when connecting a non-PMF with Qt::UniqueConnection...
...if a PMF connection had already happened. Since UniqueConnection isn't implemented for non-PMFs (functors and lambdas aren't comparable, even if static member functions or non-member functions are), we pass a null pointer for comparison argument. The disconnect() code already protected against a null pointer there, but not the connect code path with Qt::UniqueConnection Change-Id: I87e17314d8b24ae983b1fffd145324beced0494d Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Dario Freddi <dario.freddi@ispirata.com>
This commit is contained in:
parent
6d31d3e7ef
commit
32c301e229
@ -4683,7 +4683,7 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
|
|||||||
QOrderedMutexLocker locker(signalSlotLock(sender),
|
QOrderedMutexLocker locker(signalSlotLock(sender),
|
||||||
signalSlotLock(receiver));
|
signalSlotLock(receiver));
|
||||||
|
|
||||||
if (type & Qt::UniqueConnection) {
|
if (type & Qt::UniqueConnection && slot) {
|
||||||
QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists;
|
QObjectConnectionListVector *connectionLists = QObjectPrivate::get(s)->connectionLists;
|
||||||
if (connectionLists && connectionLists->count() > signal_index) {
|
if (connectionLists && connectionLists->count() > signal_index) {
|
||||||
const QObjectPrivate::Connection *c2 =
|
const QObjectPrivate::Connection *c2 =
|
||||||
|
@ -139,6 +139,7 @@ private slots:
|
|||||||
void connectFunctorOverloads();
|
void connectFunctorOverloads();
|
||||||
void connectFunctorQueued();
|
void connectFunctorQueued();
|
||||||
void connectFunctorWithContext();
|
void connectFunctorWithContext();
|
||||||
|
void connectFunctorWithContextUnique();
|
||||||
void connectFunctorDeadlock();
|
void connectFunctorDeadlock();
|
||||||
void connectStaticSlotWithObject();
|
void connectStaticSlotWithObject();
|
||||||
void disconnectDoesNotLeakFunctor();
|
void disconnectDoesNotLeakFunctor();
|
||||||
@ -5800,6 +5801,22 @@ void tst_QObject::connectFunctorWithContext()
|
|||||||
context->deleteLater();
|
context->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QObject::connectFunctorWithContextUnique()
|
||||||
|
{
|
||||||
|
// Qt::UniqueConnections currently don't work for functors, but we need to
|
||||||
|
// be sure that they don't crash. If that is implemented, change this test.
|
||||||
|
|
||||||
|
SenderObject sender;
|
||||||
|
ReceiverObject receiver;
|
||||||
|
QObject::connect(&sender, &SenderObject::signal1, &receiver, &ReceiverObject::slot1);
|
||||||
|
receiver.count_slot1 = 0;
|
||||||
|
|
||||||
|
QObject::connect(&sender, &SenderObject::signal1, &receiver, SlotFunctor(), Qt::UniqueConnection);
|
||||||
|
|
||||||
|
sender.emitSignal1();
|
||||||
|
QCOMPARE(receiver.count_slot1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
class MyFunctor
|
class MyFunctor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user