summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2023-07-22 06:49:05 +0200
committerQt Cherry-pick Bot <[email protected]>2023-08-18 16:00:26 +0000
commit6de7e0d6465816e2846b426a39eff42f7966e1d0 (patch)
treec918bebbce6cf574f97bffa163da6c0fad567f52
parent954f13545cfda26ea5a496a694cd81d28e09cc5e (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. Change-Id: I6f8bce317d5116296973a3a2e3f97db1451f579d Reviewed-by: Volker Hilsheimer <[email protected]> (cherry picked from commit 14cf4f75848180503d3c83ff1d9aeb4536c307b7) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/network/kernel/qhostinfo.cpp22
-rw-r--r--src/network/kernel/qhostinfo_p.h4
2 files changed, 22 insertions, 4 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index b751a153e3a..7564fc3197a 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 88e8c774296..9303a19fc70 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;