diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp index 948e323dbf4..6b672099ae9 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 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] diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index a7ce66ad148..4956b2a59c9 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -961,6 +961,10 @@ QDebug &QDebug::resetFormat() so that using << Qt::hex in a QDebug operator doesn't affect other QDebug operators. + QDebugStateSaver is typically used in the implementation of an operator<<() for debugging: + + \snippet tools/customtype/message.cpp custom type streaming operator + \since 5.1 */