diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-09-02 16:22:41 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-09-03 19:25:09 +0000 |
commit | 9129d2714a5e9b1ca86cf7911edee90ee13493d8 (patch) | |
tree | 7a7b36ff7ab068eba6907eb0b161c053a25e86a8 /src | |
parent | 4116fe873eae7b541d485215ce46d9224af49701 (diff) |
Implement QDebug support for QSharedPointer
... otherwise the type goes through operator bool() and prints
"true" or "false" (!).
[ChangeLog][QtCore][QSharedPointer] Added support for debug
printing via QDebug.
Change-Id: Ic3ef9b9feee8d6ca08f1dd69f20f421fea20ca00
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 86f4c6a268..4d30396cb6 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1292,6 +1292,17 @@ compile. Use qSharedPointerConstCast to cast away the constness. */ +/*! + \fn QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) + \relates QSharedPointer + \since 5.7 + + Writes the pointer tracked by \a ptr into the debug object \a debug for + debugging purposes. + + \sa {Debugging Techniques} +*/ + #include <qset.h> #include <qmutex.h> diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 279ec36a28..56e13d500f 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -153,6 +153,8 @@ template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWe template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src); +template <class T> QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr); + QT_END_NAMESPACE #endif // Q_QDOC diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 1323dd6b1c..e224b26d9f 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -55,6 +55,7 @@ QT_END_NAMESPACE #include <new> #include <QtCore/qatomic.h> #include <QtCore/qobject.h> // for qobject_cast +#include <QtCore/qdebug.h> #if QT_DEPRECATED_SINCE(5, 5) #include <QtCore/qhash.h> #endif @@ -858,6 +859,16 @@ inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2) p1.swap(p2); } +#ifndef QT_NO_DEBUG_STREAM +template <class T> +Q_INLINE_TEMPLATE QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) +{ + QDebugStateSaver saver(debug); + debug.nospace() << "QSharedPointer(" << ptr.data() << ")"; + return debug; +} +#endif + QT_END_NAMESPACE namespace std { template <class T> |