From e668837b9c3faa5c0fc29c0bac71247eb9975746 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 22 Jul 2014 11:58:55 +0200 Subject: QDebugStateSaver: Fix trailing space issues ~QDebug() removes any trailing space if autoInsertSpaces() is true. However, if one uses QDebugStateSaver the global autoInsertSpaces might be false, but a space was added by a custom operator<<. Explicitly check for this in QDebugStateSaverPrivate::restoreState. Remove any trailing space if the local state asks for adding trailing spaces, but the original one doesn't. Add a trailing space if the local state doesn't ask for one, but the global state does. Change-Id: I243b5c76d5ed2c1ec4820da35ab6e254da1551d9 Reviewed-by: David Faure --- src/corelib/io/qdebug.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 56c46d69c9..b0411f9dd9 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -438,10 +438,18 @@ public: } void restoreState() { + const bool currentSpaces = m_dbg.autoInsertSpaces(); + if (currentSpaces && !m_spaces) + if (m_dbg.stream->buffer.endsWith(QLatin1Char(' '))) + m_dbg.stream->buffer.chop(1); + m_dbg.setAutoInsertSpaces(m_spaces); m_dbg.stream->ts.d_ptr->params = m_streamParams; if (m_dbg.stream->context.version > 1) m_dbg.stream->flags = m_flags; + + if (!currentSpaces && m_spaces) + m_dbg.stream->ts << ' '; } QDebug &m_dbg; @@ -475,7 +483,6 @@ QDebugStateSaver::QDebugStateSaver(QDebug &dbg) QDebugStateSaver::~QDebugStateSaver() { d->restoreState(); - d->m_dbg.maybeSpace(); } QT_END_NAMESPACE -- cgit v1.2.3