QMetaObject: port invokeMethodImpl() from QScopeGuard to SlotObjUniquePtr

... so it can use the new QMetaCallEvent() ctors taking that type.

As a consequence, the slot object ref-count is now no longer touched
on the way into the meta-call event (was: upped in QMetaCallEvent
ctor, then downed in QScopeGuard).

Pick-to: 6.6 6.5
Change-Id: Id9bd157792458a3834809c23e94ca5f504f7abd1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2023-07-19 14:49:08 +02:00
parent 00dbd3cd26
commit 4015f81d31
1 changed files with 5 additions and 4 deletions

View File

@ -1611,9 +1611,10 @@ bool QMetaObject::invokeMethodImpl(QObject *obj, const char *member, Qt::Connect
return printMethodNotFoundWarning(obj->metaObject(), name, paramCount, typeNames, metaTypes);
}
bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret)
bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj,
Qt::ConnectionType type, void *ret)
{
auto slotGuard = qScopeGuard([slot] { slot->destroyIfLastRef(); });
auto slot = QtPrivate::SlotObjUniquePtr(slotObj);
if (! object)
return false;
@ -1638,14 +1639,14 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
return false;
}
QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, 1));
QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, 1));
} else if (type == Qt::BlockingQueuedConnection) {
#if QT_CONFIG(thread)
if (receiverInSameThread)
qWarning("QMetaObject::invokeMethod: Dead lock detected");
QSemaphore semaphore;
QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, argv, &semaphore));
QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, argv, &semaphore));
semaphore.acquire();
#endif // QT_CONFIG(thread)
} else {