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:
parent
426740ba1d
commit
6354e7d37c
@ -107,7 +107,7 @@ void QHostInfoResult::postResultsReady(const QHostInfo &info)
|
|||||||
auto result = new QHostInfoResult(this);
|
auto result = new QHostInfoResult(this);
|
||||||
Q_CHECK_PTR(result);
|
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);
|
Q_CHECK_PTR(metaCallEvent);
|
||||||
qApp->postEvent(result, metaCallEvent);
|
qApp->postEvent(result, metaCallEvent);
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,6 @@ public:
|
|||||||
moveToThread(receiver->thread());
|
moveToThread(receiver->thread());
|
||||||
}
|
}
|
||||||
|
|
||||||
~QHostInfoResult()
|
|
||||||
{
|
|
||||||
if (slotObj)
|
|
||||||
slotObj->destroyIfLastRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
void postResultsReady(const QHostInfo &info);
|
void postResultsReady(const QHostInfo &info);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
@ -67,11 +61,11 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QHostInfoResult(const QHostInfoResult *other)
|
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)
|
withContextObject(other->withContextObject)
|
||||||
{
|
{
|
||||||
if (slotObj)
|
if (slotObj)
|
||||||
slotObj->ref();
|
slotObj->ref(); // ... and ref it here
|
||||||
// cleanup if the application terminates before results are delivered
|
// cleanup if the application terminates before results are delivered
|
||||||
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
|
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
|
||||||
this, &QObject::deleteLater);
|
this, &QObject::deleteLater);
|
||||||
@ -80,7 +74,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPointer<const QObject> receiver = nullptr;
|
QPointer<const QObject> receiver = nullptr;
|
||||||
QtPrivate::QSlotObjectBase *slotObj = nullptr;
|
QtPrivate::SlotObjUniquePtr slotObj;
|
||||||
const bool withContextObject = false;
|
const bool withContextObject = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user