QDebugStateSaver Class
Classe di convenienza per operatori personalizzati di tipo “ QDebug ”. Altro...
| Intestazione: | #include <QDebugStateSaver> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
Funzioni pubbliche
| QDebugStateSaver(QDebug &dbg) | |
| ~QDebugStateSaver() |
Descrizione dettagliata
Salva le impostazioni utilizzate da ` QDebug` e le ripristina al momento della distruzione, quindi chiama ` maybeSpace()` per separare gli argomenti con uno spazio se ` autoInsertSpaces()` era vero al momento della creazione di `QDebugStateSaver`.
L'inserimento automatico di spazi tra le scritture è una delle impostazioni che QDebugStateSaver memorizza per la durata del blocco corrente.
Vengono salvate e ripristinate anche le impostazioni dell’ QTextStream interno, in modo che l’uso di << Qt::hex in un operatore QDebug non influisca sugli altri operatori QDebug.
QDebugStateSaver viene tipicamente utilizzato nell’implementazione di un operatore <<() per il debug:
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;
}Documentazione delle funzioni membro
QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
Crea un'istanza di QDebugStateSaver, che salva le impostazioni attualmente utilizzate da dbg.
Vedi anche QDebug::setAutoInsertSpaces() e QDebug::autoInsertSpaces().
[noexcept] QDebugStateSaver::~QDebugStateSaver()
Elimina un'istanza di QDebugStateSaver, ripristinando così le impostazioni utilizzate al momento della creazione dell'istanza di QDebugStateSaver.
Vedi anche 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.