summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2022-03-12 11:05:12 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-16 17:30:47 +0000
commit325d23789968bdbbb8345a0b6c7e25c1dc919b51 (patch)
tree4aa6742bd4d42b219482bd8b05ec0f664e2cd664 /examples
parent07840819fcf70e4b49f01ed22f627568c0e0df15 (diff)
Use QDebugStateSaver in example operator<<()
This makes sure that changes in the debug stream - like nospace() - do not "leak". Also use the example snippet in QDebugStateSaver documentation. Change-Id: I934976d2c7c2335abfec68c763526a5cbb0e6f1e Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 9f5f64e9dbd916679bd881ee0331da9a3dacac32) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/tools/customtype/message.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp
index 948e323dbf..6b672099ae 100644
--- a/examples/corelib/tools/customtype/message.cpp
+++ b/examples/corelib/tools/customtype/message.cpp
@@ -60,6 +60,7 @@ Message::Message(const QString &body, const QStringList &headers)
//! [custom type streaming operator]
QDebug operator<<(QDebug dbg, const Message &message)
{
+ QDebugStateSaver saver(dbg);
QList<QStringView> pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts);
if (pieces.isEmpty())
dbg.nospace() << "Message()";
@@ -67,7 +68,7 @@ QDebug operator<<(QDebug dbg, const Message &message)
dbg.nospace() << "Message(" << pieces.first() << ")";
else
dbg.nospace() << "Message(" << pieces.first() << " ...)";
- return dbg.maybeSpace();
+ return dbg;
}
//! [custom type streaming operator]