QDebugStateSaver Class
头文件: | #include <QDebugStateSaver> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
公共函数
QDebugStateSaver(QDebug &dbg) | |
~QDebugStateSaver() |
详细说明
保存QDebug 使用的设置,并在销毁时恢复它们,然后调用maybeSpace() ,如果autoInsertSpaces() 在构造 QDebugStateSaver 时为真,则用空格分隔参数。
在写入之间自动插入空格是 QDebugStateSaver 在当前程序块期间存储的设置之一。
内部QTextStream 的设置也会被保存和恢复,因此在QDebug 操作符中使用 <<Qt::hex 不会影响其他QDebug 操作符。
QDebugStateSaver 通常用于实现用于调试的操作符<<():
QDebug operator<<(QDebug dbg, const Message &message) { 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; }
成员函数文档
QDebugStateSaver::QDebugStateSaver(QDebug &dbg)
创建 QDebugStateSaver 实例,保存dbg 当前使用的设置。
另请参阅 QDebug::setAutoInsertSpaces() 和QDebug::autoInsertSpaces() 。
[noexcept]
QDebugStateSaver::~QDebugStateSaver()
销毁QDebugStateSaver 实例,恢复QDebugStateSaver 实例创建时使用的设置。
另请参阅 QDebug::setAutoInsertSpaces() 和QDebug::autoInsertSpaces()。
© 2025 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.