QDebugStateSaver Class
Clase de conveniencia para operadores personalizados de « QDebug ». Más información...
| Encabezado: | #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 la configuración utilizada por ` QDebug` y la restaura al destruirse; a continuación, llama a ` maybeSpace()`, para separar los argumentos con un espacio si ` autoInsertSpaces()` era verdadero en el momento de crear el `QDebugStateSaver`.
La inserción automática de espacios entre las entradas es una de las configuraciones que QDebugStateSaver almacena mientras dure el bloque actual.
Los ajustes del QTextStream interno también se guardan y se restauran, de modo que el uso de << Qt::hex en un operador QDebug no afecta a otros operadores QDebug.
QDebugStateSaver se utiliza habitualmente en la implementación de un operador <<() con fines de 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 las funciones miembro
QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
Crea una instancia de `QDebugStateSaver`, que guarda la configuración que utiliza actualmente ` dbg`.
Véase también QDebug::setAutoInsertSpaces() y QDebug::autoInsertSpaces().
[noexcept] QDebugStateSaver::~QDebugStateSaver()
Elimina una instancia de « QDebugStateSaver », lo que restaura la configuración utilizada cuando se creó la instancia de « 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.