summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2023-07-21 12:32:53 +0200
committerQt Cherry-pick Bot <[email protected]>2023-08-07 06:28:48 +0000
commite54810d86b50a3b55225a6b7e00203b0e633cbbf (patch)
tree2cc534b0ea08222a79d6d887f5c9c87449fc1fb0
parent6354e7d37c73bfaf709a77215c4b49e132a44f26 (diff)
Add copy(SlotObjUniquePtr), use it in QHostInfoResult & SlotObjSharedPtr
It's a free function, because a) it rhymes with move(ptr) and, of course, SlotObjUniquePtr being a std::unique_ptr, b) we can't add member functions to it (and no, inheriting from a type whose dtor is neither protected nor virtual is nothing you will catch yours truly doing). Change-Id: I2026126857a7bba204d683bad118e8a2c5cb2924 Reviewed-by: Ivan Solovev <[email protected]> (cherry picked from commit a9982a3b637e482c52a1ca97f9e235eb302048c3) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/corelib/kernel/qobjectdefs_impl.h12
-rw-r--r--src/network/kernel/qhostinfo_p.h4
2 files changed, 8 insertions, 8 deletions
diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h
index 68da6e04e79..a45792c5d7f 100644
--- a/src/corelib/kernel/qobjectdefs_impl.h
+++ b/src/corelib/kernel/qobjectdefs_impl.h
@@ -452,6 +452,12 @@ namespace QtPrivate {
using SlotObjUniquePtr = std::unique_ptr<QSlotObjectBase,
QSlotObjectBase::Deleter>;
+ inline SlotObjUniquePtr copy(const SlotObjUniquePtr &other) noexcept
+ {
+ if (other)
+ other->ref();
+ return SlotObjUniquePtr{other.get()};
+ }
class SlotObjSharedPtr {
SlotObjUniquePtr obj;
@@ -465,11 +471,7 @@ namespace QtPrivate {
// (that's why (QSlotObjectBase*) ctor doesn't exisit: don't know whether that one _should_)
}
Q_NODISCARD_CTOR SlotObjSharedPtr(const SlotObjSharedPtr &other) noexcept
- : obj(other.obj.get())
- {
- if (obj)
- obj->ref();
- }
+ : obj{copy(other.obj)} {}
SlotObjSharedPtr &operator=(const SlotObjSharedPtr &other) noexcept
{ auto copy = other; swap(copy); return *this; }
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index d883a33cdd2..6b755ab0c2c 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -61,11 +61,9 @@ protected:
private:
QHostInfoResult(const QHostInfoResult *other)
- : receiver(other->receiver), slotObj(other->slotObj.get()), // ugly, but copy the pointer...
+ : receiver(other->receiver), slotObj{copy(other->slotObj)},
withContextObject(other->withContextObject)
{
- if (slotObj)
- slotObj->ref(); // ... and ref it here
// cleanup if the application terminates before results are delivered
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit,
this, &QObject::deleteLater);