QDebugStateSaver Class
Classe de conveniência para operadores personalizados de ` QDebug `. Mais...
| Cabeçalho: | #include <QDebugStateSaver> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
Funções públicas
| QDebugStateSaver(QDebug &dbg) | |
| ~QDebugStateSaver() |
Descrição detalhada
Salva as configurações utilizadas por ` QDebug` e as restaura no momento da destruição; em seguida, chama ` maybeSpace()` para separar os argumentos com um espaço, caso ` autoInsertSpaces()` estivesse definido como verdadeiro no momento da construção do `QDebugStateSaver`.
A inserção automática de espaços entre as gravações é uma das configurações que o `QDebugStateSaver` armazena durante o bloco atual.
As configurações do QTextStream interno também são salvas e restauradas, de modo que o uso de << Qt::hex em um operador QDebug não afeta outros operadores QDebug.
O `QDebugStateSaver` é normalmente usado na implementação de um operador <<() para depuração:
QDebug operator<<(QDebug dbg, const Message &message)
{
QDebugStateSaver saver(dbg);
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;
}Documentação das funções-membro
QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
Cria uma instância de QDebugStateSaver, que salva as configurações atualmente utilizadas pelo dbg.
Veja também ` QDebug::setAutoInsertSpaces()` e ` QDebug::autoInsertSpaces()`.
[noexcept] QDebugStateSaver::~QDebugStateSaver()
Destrói uma instância do QDebugStateSaver, o que restaura as configurações utilizadas quando a instância do QDebugStateSaver foi criada.
Veja também QDebug::setAutoInsertSpaces() e QDebug::autoInsertSpaces().
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.