From 7edd623957b958d7d3db20772571810d7be9da85 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 1 Feb 2012 20:47:26 +0100 Subject: Fix QTextStream and QDebug operator<< for QLatin1String QLatin1String now has a constructor that takes explicit length, which makes it possible to create a QLatin1String that isn't null-terminated. Made the QTextStream and QDebug << operators work in that case. Change-Id: I94d051ce2ebfb2d2a403b96d25e040c80a54bf7c Reviewed-by: Lars Knoll --- src/corelib/io/qdebug.h | 2 +- src/corelib/io/qtextstream.cpp | 15 +++++++++++++++ src/corelib/io/qtextstream.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index c268660573..48a382eea6 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -113,7 +113,7 @@ public: inline QDebug &operator<<(const char* t) { stream->ts << QString::fromAscii(t); return maybeSpace(); } inline QDebug &operator<<(const QString & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } inline QDebug &operator<<(const QStringRef & t) { return operator<<(t.toString()); } - inline QDebug &operator<<(const QLatin1String &t) { stream->ts << '\"' << t.latin1() << '\"'; return maybeSpace(); } + inline QDebug &operator<<(const QLatin1String &t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } inline QDebug &operator<<(const QByteArray & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(QTextStreamFunction f) { diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 7ea00ceec2..7f37866226 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -2530,6 +2530,21 @@ QTextStream &QTextStream::operator<<(const QString &string) return *this; } +/*! + \overload + + Writes \a string to the stream, and returns a reference to the + QTextStream. The contents of \a string are converted with the + QString constructor that takes a QLatin1String as argument. +*/ +QTextStream &QTextStream::operator<<(const QLatin1String &string) +{ + Q_D(QTextStream); + CHECK_VALID_STREAM(*this); + d->putString(QString(string)); + return *this; +} + /*! \overload diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index 3e1d0faa25..011d43ebb0 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -187,6 +187,7 @@ public: QTextStream &operator<<(float f); QTextStream &operator<<(double f); QTextStream &operator<<(const QString &s); + QTextStream &operator<<(const QLatin1String &s); QTextStream &operator<<(const QByteArray &array); QTextStream &operator<<(const char *c); QTextStream &operator<<(const void *ptr); -- cgit v1.2.3