QDebugStateSaver Class
Clase de conveniencia para operadores QDebug personalizados. Más...
| Cabecera: | #include <QDebugStateSaver> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core)target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
Funciones públicas
| QDebugStateSaver(QDebug &dbg) | |
| ~QDebugStateSaver() |
Descripción detallada
Guarda las configuraciones usadas por QDebug, y las restaura al destruirse, luego llama a maybeSpace(), para separar los argumentos con un espacio si autoInsertSpaces() era true al momento de construir el QDebugStateSaver.
La inserción automática de espacios entre escrituras es uno de los ajustes que QDebugStateSaver almacena para la duración del bloque actual.
Los ajustes del QTextStream interno también se guardan y restauran, de modo que el uso de << Qt::hex en un operador QDebug no afecta a otros operadores QDebug.
QDebugStateSaver se utiliza típicamente en la implementación de un operador<<() para depuración:
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; }
Documentación de funciones miembro
QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
Crea una instancia de QDebugStateSaver, que guarda la configuración utilizada actualmente por dbg.
Véase también QDebug::setAutoInsertSpaces() y QDebug::autoInsertSpaces().
[noexcept] QDebugStateSaver::~QDebugStateSaver()
Destruye una instancia QDebugStateSaver, que restaura la configuración utilizada cuando se creó la instancia QDebugStateSaver.
Véase también QDebug::setAutoInsertSpaces() y 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.