Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QDebugStateSaver Class Reference

\inmodule QtCore More...

+ Collaboration diagram for QDebugStateSaver:

Detailed Description

\inmodule QtCore

Convenience class for custom QDebug operators.

Saves the settings used by QDebug, and restores them upon destruction, then calls \l {QDebug::maybeSpace()}{maybeSpace()}, to separate arguments with a space if \l {QDebug::autoInsertSpaces()}{autoInsertSpaces()} was true at the time of constructing the QDebugStateSaver.

The automatic insertion of spaces between writes is one of the settings that QDebugStateSaver stores for the duration of the current block.

The settings of the internal QTextStream are also saved and restored, 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:

{
const QList<QStringView> pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts);
if (pieces.isEmpty())
dbg.nospace() << "Message()";
else if (pieces.size() == 1)
dbg.nospace() << "Message(" << pieces.first() << ")";
else
dbg.nospace() << "Message(" << pieces.first() << " ...)";
return dbg;
}
Since
5.1

The documentation for this class was generated from the following file: