From f6d0c67d30ef1c22b086641e8d1288e1baaa1663 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 13 Feb 2014 14:44:38 +0100 Subject: [PATCH] QDebug: Allow text stream formatting for 64 bit numbers Use the QTextStream stream operator for formatting 64 bit numbers, just like we do for other numbers, too. This ensures all numbers in a QDebug stream e.g. respect the hex and showbase modifiers. The original reason for formatting qin64, quint64 with QString::number is unclear (pre-dates the original qt4 git import). Maybe QTextStream did lack proper support for 64 bit numbers back then. Task-number: QTBUG-36841 Change-Id: I049516c2a8394c9c1a708f86c3d950418a20a957 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/io/qdebug.h | 6 ++---- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 00177b659e8..bdaaa05768c 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -110,10 +110,8 @@ public: inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(signed long t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(unsigned long t) { stream->ts << t; return maybeSpace(); } - inline QDebug &operator<<(qint64 t) - { stream->ts << QString::number(t); return maybeSpace(); } - inline QDebug &operator<<(quint64 t) - { stream->ts << QString::number(t); return maybeSpace(); } + inline QDebug &operator<<(qint64 t) { stream->ts << t; return maybeSpace(); } + inline QDebug &operator<<(quint64 t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); } diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 29c7e6a81eb..80144dba202 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -57,6 +57,7 @@ private slots: void veryLongWarningMessage() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; + void textStreamModifiers() const; void defaultMessagehandler() const; }; @@ -280,6 +281,18 @@ void tst_QDebug::qDebugQLatin1String() const QCOMPARE(QString::fromLatin1(s_function), function); } +void tst_QDebug::textStreamModifiers() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { qDebug() << hex << short(0xf) << int(0xf) << unsigned(0xf) << long(0xf) << qint64(0xf) << quint64(0xf); } + QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("f f f f f f")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + void tst_QDebug::defaultMessagehandler() const { MessageHandlerSetter mhs(0);