diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-03-09 11:46:26 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-03 22:35:57 +0200 |
commit | e3a8e242ada146b1ec796424696e6c3964ab36dc (patch) | |
tree | 2247cea75ee30120b0e16fc007f0608092f87201 /src/corelib | |
parent | ef2a2a9c03b6cce57375bd998633d759a4ec1b3f (diff) |
QWeakPointer: add lock() for std::weak_ptr compatibility
[ChangeLog][QtCore][QWeakPointer] Added lock() method for std::weak_ptr compatibility.
Change-Id: I0851d91c51f5a4f04a855a1d8082234ce38396b4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 9 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 2 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index a610fc46e5..19c88fcf1c 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -894,6 +894,15 @@ */ /*! + \fn QSharedPointer<T> QWeakPointer::lock() const + \since 5.4 + + Same as toStrongRef(). + + This function is provided for API compatibility with std::weak_ptr. +*/ + +/*! \fn void QWeakPointer::clear() Clears this QWeakPointer object, dropping the reference that it diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 34b4bfbb12..ea9b4fbf27 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -126,6 +126,7 @@ public: void clear(); QSharedPointer<T> toStrongRef() const; + QSharedPointer<T> lock() const; }; template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2); diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index c077b84492..e59efce7ae 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -639,6 +639,8 @@ public: inline void clear() { *this = QWeakPointer(); } inline QSharedPointer<T> toStrongRef() const { return QSharedPointer<T>(*this); } + // std::weak_ptr compatibility: + inline QSharedPointer<T> lock() const { return toStrongRef(); } #if defined(QWEAKPOINTER_ENABLE_ARROW) inline T *operator->() const { return data(); } |