IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QDebugStateSaver Class

Convenience class for custom QDebug operators.

This class was introduced in Qt 5.1.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QDebugStateSaver Class

  • Header: QDebugStateSaver

  • Since: Qt 5.1

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

Detailed Description

Saves the settings used by QDebug, and restores them upon destruction, then calls maybeSpace(), to separate arguments with a space if 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:

 
Sélectionnez
QDebug operator&lt;&lt;(QDebug dbg, const Message &amp;message)
{
    QDebugStateSaver saver(dbg);
    QList&lt;QStringView&gt; pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts);
    if (pieces.isEmpty())
        dbg.nospace() &lt;&lt; "Message()";
    else if (pieces.size() == 1)
        dbg.nospace() &lt;&lt; "Message(" &lt;&lt; pieces.first() &lt;&lt; ")";
    else
        dbg.nospace() &lt;&lt; "Message(" &lt;&lt; pieces.first() &lt;&lt; " ...)";
    return dbg;
}

Member Function Documentation

 

QDebugStateSaver::QDebugStateSaver(QDebug &dbg)

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

See Also

QDebugStateSaver::~QDebugStateSaver()

Destroys a QDebugStateSaver instance, which restores the settings used when the QDebugStateSaver instance was created.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+