QHostInfo: use SlotObjUniquePtr

Drops the direct deref'ing.

Change-Id: I9f159244d50572659fa8e9cabfbef47e769ac54e
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 5bb4020cbe3ce0619d6046708b677469415de850)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2023-07-18 12:21:26 +02:00 committed by Qt Cherry-pick Bot
parent 426740ba1d
commit 6354e7d37c
2 changed files with 4 additions and 10 deletions

View File

@ -107,7 +107,7 @@ void QHostInfoResult::postResultsReady(const QHostInfo &info)
auto result = new QHostInfoResult(this);
Q_CHECK_PTR(result);
auto metaCallEvent = QMetaCallEvent::create(slotObj, nullptr, signal_index, info);
auto metaCallEvent = QMetaCallEvent::create(slotObj.get(), nullptr, signal_index, info);
Q_CHECK_PTR(metaCallEvent);
qApp->postEvent(result, metaCallEvent);
}

View File

@ -51,12 +51,6 @@ public:
moveToThread(receiver->thread());
}
~QHostInfoResult()
{
if (slotObj)
slotObj->destroyIfLastRef();
}
void postResultsReady(const QHostInfo &info);
Q_SIGNALS:
@ -67,11 +61,11 @@ protected:
private:
QHostInfoResult(const QHostInfoResult *other)
: receiver(other->receiver), slotObj(other->slotObj),
: receiver(other->receiver), slotObj(other->slotObj.get()), // ugly, but copy the pointer...
withContextObject(other->withContextObject)
{
if (slotObj)
slotObj->ref();
slotObj->ref(); // ... and ref it here
// cleanup if the application terminates before results are delivered
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
this, &QObject::deleteLater);
@ -80,7 +74,7 @@ private:
}
QPointer<const QObject> receiver = nullptr;
QtPrivate::QSlotObjectBase *slotObj = nullptr;
QtPrivate::SlotObjUniquePtr slotObj;
const bool withContextObject = false;
};