diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-07-22 06:49:05 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-08-18 16:00:09 +0000 |
commit | 14cf4f75848180503d3c83ff1d9aeb4536c307b7 (patch) | |
tree | d56aad6990730c894175ca140211e66df8f8e26c /src/network/kernel | |
parent | 17e7d98626b21e55d1ca8eb638859e025bf0ec9a (diff) |
QHostInfo: add -Result and -Runnable ctors taking SlotObjUniquePtr
... and use them around the code.
Avoids the impedance mismatch between users, which .release() their
SlotObjUniquePtr's into the ctors, and the ctor, which constructs its
member SlotObjUniquePtr from that.
The old constructors are left in on purpose and removed in a follow-up
commit to facilitate cherry-picking into branches that might have
additional callers.
Pick-to: 6.6 6.5
Change-Id: I6f8bce317d5116296973a3a2e3f97db1451f579d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 22 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_p.h | 4 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index b751a153e3..7564fc3197 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -72,6 +72,13 @@ Q_APPLICATION_STATIC(QHostInfoLookupManager, theHostInfoLookupManager) } +QHostInfoResult::QHostInfoResult(const QObject *receiver, QtPrivate::SlotObjUniquePtr slot) + : receiver{receiver}, slotObj{std::move(slot)}, withContextObject{slotObj && receiver} +{ + if (receiver) + moveToThread(receiver->thread()); +} + QHostInfoResult::~QHostInfoResult() = default; @@ -758,7 +765,7 @@ int QHostInfo::lookupHostImpl(const QString &name, hostInfo.setError(QHostInfo::HostNotFound); hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given")); - QHostInfoResult result(receiver, slotObj.release()); + QHostInfoResult result(receiver, std::move(slotObj)); if (receiver && member) QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); @@ -775,7 +782,7 @@ int QHostInfo::lookupHostImpl(const QString &name, QHostInfo hostInfo = QHostInfoAgent::lookup(name); hostInfo.setLookupId(id); - QHostInfoResult result(receiver, slotObj.release()); + QHostInfoResult result(receiver, std::move(slotObj)); if (receiver && member) QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); @@ -791,7 +798,7 @@ int QHostInfo::lookupHostImpl(const QString &name, QHostInfo info = manager->cache.get(name, &valid); if (valid) { info.setLookupId(id); - QHostInfoResult result(receiver, slotObj.release()); + QHostInfoResult result(receiver, std::move(slotObj)); if (receiver && member) QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); @@ -801,7 +808,7 @@ int QHostInfo::lookupHostImpl(const QString &name, } // cache is not enabled or it was not in the cache, do normal lookup - QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, slotObj.release()); + QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, std::move(slotObj)); if (receiver && member) QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); @@ -818,6 +825,13 @@ QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i, const QObject *re setAutoDelete(true); } +QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i, const QObject *receiver, + QtPrivate::SlotObjUniquePtr slotObj) + : toBeLookedUp{hn}, id{i}, resultEmitter{receiver, std::move(slotObj)} +{ + setAutoDelete(true); +} + QHostInfoRunnable::~QHostInfoRunnable() = default; diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 88e8c77429..9303a19fc7 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -51,6 +51,8 @@ public: moveToThread(receiver->thread()); } + explicit QHostInfoResult(const QObject *receiver, QtPrivate::SlotObjUniquePtr slot); + ~QHostInfoResult() override; void postResultsReady(const QHostInfo &info); @@ -145,6 +147,8 @@ 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; |