summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdebug.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-04-20 17:35:22 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-05-06 17:54:23 +0000
commita2551c45d496c23045eb8451e080e75b2f8b42c1 (patch)
tree66ce1e4a0cb5341a34150d410484b4ff6e8009f2 /src/corelib/io/qdebug.h
parent59f8da17e6a2989b072254970d23281301114503 (diff)
Move the formatting of <chrono> durations to QDebug & QtTest
[ChangeLog][QtCore][QDebug] Added pretty formatting of C++ <chrono> durations. [ChangeLog][QtTest] Added pretty formatting of C++ <chrono> durations for QCOMPARE expressions. Change-Id: I3b169860d8bd41e9be6bfffd1757cc087ba957fa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/io/qdebug.h')
-rw-r--r--src/corelib/io/qdebug.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index e39f9afd316..3fa9c420525 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -16,6 +16,7 @@
#include <QtCore/qsharedpointer.h>
// all these have already been included by various headers above, but don't rely on indirect includes:
+#include <chrono>
#include <list>
#include <map>
#include <string>
@@ -67,6 +68,7 @@ class QT6_ONLY(Q_CORE_EXPORT) QDebug : public QIODeviceBase
QT7_ONLY(Q_CORE_EXPORT) void putUcs4(uint ucs4);
QT7_ONLY(Q_CORE_EXPORT) void putString(const QChar *begin, size_t length);
QT7_ONLY(Q_CORE_EXPORT) void putByteArray(const char *begin, size_t length, Latin1Content content);
+ QT7_ONLY(Q_CORE_EXPORT) static QByteArray timeUnit(qint64 num, qint64 den);
public:
explicit QDebug(QIODevice *device) : stream(new Stream(device)) {}
explicit QDebug(QString *string) : stream(new Stream(string)) {}
@@ -189,6 +191,13 @@ public:
{ return *this << QString::fromUcs4(s.data(), s.size()); }
#endif // !Q_QDOC
+ template <typename Rep, typename Period>
+ QDebug &operator<<(std::chrono::duration<Rep, Period> duration)
+ {
+ stream->ts << duration.count() << timeUnit(Period::num, Period::den);
+ return maybeSpace();
+ }
+
template <typename T>
static QString toString(T &&object)
{