diff options
Diffstat (limited to 'src/network/kernel/qhostinfo_p.h')
-rw-r--r-- | src/network/kernel/qhostinfo_p.h | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 2176b464ae..b229eb1cd8 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -43,26 +43,21 @@ class QHostInfoResult : public QObject { Q_OBJECT public: - QHostInfoResult(const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) - : receiver(receiver), slotObj(slotObj), - withContextObject(slotObj && receiver) - { - if (receiver) - moveToThread(receiver->thread()); - } + explicit QHostInfoResult(const QObject *receiver, QtPrivate::SlotObjUniquePtr slot); + ~QHostInfoResult() override; void postResultsReady(const QHostInfo &info); Q_SIGNALS: void resultsReady(const QHostInfo &info); -protected: - bool event(QEvent *event) override; +private Q_SLOTS: + void finalizePostResultsReady(const QHostInfo &info); private: - QHostInfoResult(const QHostInfoResult *other) - : receiver(other->receiver), slotObj(other->slotObj), - withContextObject(other->withContextObject) + QHostInfoResult(QHostInfoResult *other) + : receiver(other->receiver.get() != other ? other->receiver.get() : this), + slotObj{std::move(other->slotObj)} { // cleanup if the application terminates before results are delivered connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, @@ -71,9 +66,10 @@ private: moveToThread(other->thread()); } + // receiver is either a QObject provided by the user, + // or it's set to `this` (to emulate the behavior of the contextless connect()) QPointer<const QObject> receiver = nullptr; - QtPrivate::QSlotObjectBase *slotObj = nullptr; - const bool withContextObject = false; + QtPrivate::SlotObjUniquePtr slotObj; }; class QHostInfoAgent @@ -141,8 +137,10 @@ private: class QHostInfoRunnable : public QRunnable { public: - QHostInfoRunnable(const QString &hn, int i, const QObject *receiver, - QtPrivate::QSlotObjectBase *slotObj); + explicit QHostInfoRunnable(const QString &hn, int i, const QObject *receiver, + QtPrivate::SlotObjUniquePtr slotObj); + ~QHostInfoRunnable() override; + void run() override; QString toBeLookedUp; |