CopperSpice API  1.9.2
QDebugStateSaver Class Reference

Custom QDebug operators. More...

Public Methods

 QDebugStateSaver (QDebug &debug)
 
 ~QDebugStateSaver ()
 

Detailed Description

Saves the settings used by QDebug and restores the state when the QSebugStateSaver is destroyed.

Example

QDebugStateSaver is typically used in the implementation of an operator<<() method.

QDebug operator<<(QDebug debug, const Message &message)
{
QDebugStateSaver saver(debug);
QList<QStringView> lines = message.body().split("\r\n", QStringParser::SkipEmptyParts);
if (lines.isEmpty()) {
debug.nospace() << "Message()";
} else if (lines.size() == 1) {
debug.nospace() << "Message(" << lines.first() << ")";
} else {
debug.nospace() << "Message(" << lines.first() << " ...)";
}
return debug;
}

Constructor & Destructor Documentation

QDebugStateSaver::QDebugStateSaver ( QDebug debug)

Creates a QDebugStateSaver object which saves the settings currently used by debug.

See also
QDebug::setAutoInsertSpaces(), QDebug::autoInsertSpaces()
QDebugStateSaver::~QDebugStateSaver ( )

Destroys the current QDebugStateSaver object and restores the settings used when the QDebugStateSaver object was created.

See also
QDebug::setAutoInsertSpaces(), QDebug::autoInsertSpaces().