diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 58c62f0a3e8..50e555d968b 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -697,6 +697,35 @@ the pointer itself will be deleted. */ +/*! + \fn void QSharedPointer::reset() + \since 5.0 + + Same as clear(). For std::shared_ptr compatibility. +*/ + +/*! + \fn void QSharedPointer::reset(T *t) + \since 5.0 + + Resets this QSharedPointer object to point to \a t + instead. Equivalent to: + \code + QSharedPointer other(t); this->swap(other); + \endcode +*/ + +/*! + \fn void QSharedPointer::reset(T *t, Deleter deleter) + \since 5.0 + + Resets this QSharedPointer object to point to \a t + instead, with deleter \a deleter. Equivalent to: + \code + QSharedPointer other(t, deleter); this->swap(other); + \endcode +*/ + /*! \fn QWeakPointer::QWeakPointer() diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 4033b5d4229..b0a1b7619d9 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -85,6 +85,11 @@ public: void clear(); + void reset(); + void reset(T *t); + template + void reset(T *t, Deleter deleter); + // casts: template QSharedPointer staticCast() const; template QSharedPointer dynamicCast() const; diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 81ce17889e0..fadb4e05864 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -510,6 +510,13 @@ public: inline void swap(QSharedPointer &other) { QSharedPointer::internalSwap(other); } + inline void reset() { clear(); } + inline void reset(T *t) + { QSharedPointer copy(t); swap(copy); } + template + inline void reset(T *t, Deleter deleter) + { QSharedPointer copy(t, deleter); swap(copy); } + template QSharedPointer staticCast() const {