CopperSpice API  1.9.1
QDebugStateSaver Class Reference

Custom QDebug operators. More...

Public Methods

 QDebugStateSaver (QDebug &dbg)
 
 ~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<<() for debugging.

QDebug operator<<(QDebug dbg, const Message &message)
{
QDebugStateSaver saver(dbg);
QList<QStringView> pieces = message.body().split("\r\n", QStringParser::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;
}

Constructor & Destructor Documentation

QDebugStateSaver::QDebugStateSaver ( QDebug dbg)

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

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().