From 658b9697f9d85d4ed294810b4f60bafdbdd8e247 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 19 Feb 2020 11:29:37 +0100 Subject: Add QDebug::toString() This template function streams the given object into a QDebug instance that operates on a string, and then returns that string. This function is useful for cases where you need the textual representation of an object for debugging, but cannot use operator<<. A good example of this is when writing tests where you want to provide a useful failure message involving details about an object, but must provide it in a string to e.g. QVERIFY2. [ChangeLog][QtCore][QDebug] Added static template toString() function, which streams the given object into a QDebug instance that operates on a string, and then returns that string. Fixes: QTBUG-82309 Change-Id: I8411394e899dedad19cec788d779a4515d52ba11 Reviewed-by: Volker Hilsheimer --- src/corelib/io/qdebug.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index d13e94e096c..11f2b9f3c9d 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -713,6 +713,20 @@ QDebug &QDebug::resetFormat() \internal */ +/*! + \fn template QString QDebug::toString(const T &object) + \since 6.0 + + \include qdebug-toString.qdocinc +*/ + +/*! + \fn template QString QDebug::toString(const T *object) + \since 6.0 + + \include qdebug-toString.qdocinc +*/ + /*! \fn template QDebug operator<<(QDebug debug, const QList &list) \relates QDebug -- cgit v1.2.3