From 6354e7d37c73bfaf709a77215c4b49e132a44f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 18 Jul 2023 12:21:26 +0200 Subject: [PATCH] QHostInfo: use SlotObjUniquePtr Drops the direct deref'ing. Change-Id: I9f159244d50572659fa8e9cabfbef47e769ac54e Reviewed-by: Timur Pocheptsov Reviewed-by: Marc Mutz (cherry picked from commit 5bb4020cbe3ce0619d6046708b677469415de850) Reviewed-by: Qt Cherry-pick Bot --- src/network/kernel/qhostinfo.cpp | 2 +- src/network/kernel/qhostinfo_p.h | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index e6cba483f9d..d15c4f27ca1 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -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); } diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 28654f4e141..d883a33cdd2 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -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 receiver = nullptr; - QtPrivate::QSlotObjectBase *slotObj = nullptr; + QtPrivate::SlotObjUniquePtr slotObj; const bool withContextObject = false; };