このページでは

QDebugStateSaver Class

QDebug のカスタム演算子用の利便性クラス。詳細...

ヘッダー: #include <QDebugStateSaver>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

パブリック関数

詳細な説明

QDebug で使用される設定を保存し、破棄時にそれらを復元した後、maybeSpace() を呼び出します。これは、QDebugStateSaver の構築時にautoInsertSpaces() が true だった場合、引数をスペースで区切るためです。

書き込みの間にスペースを自動的に挿入することは、QDebugStateSaver が現在のブロックの期間中保存する設定の 1 つです。

内部の `QTextStream ` の設定も保存および復元されるため、QDebug 演算子内で <<Qt::hex を使用しても、他のQDebug 演算子には影響しません。

QDebugStateSaverは通常、デバッグ用の演算子<<()の実装で使用されます:

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;
}

メンバ関数のドキュメント

QDebugStateSaver::QDebugStateSaver(QDebug &dbg)

dbg で現在使用されている設定を保存する QDebugStateSaver インスタンスを作成します。

QDebug::setAutoInsertSpaces() およびQDebug::autoInsertSpaces()も参照してください 。

[noexcept] QDebugStateSaver::~QDebugStateSaver()

QDebugStateSaver インスタンスを破棄します。これにより、QDebugStateSaver インスタンスが作成された際に使用された設定が復元されます。

QDebug::setAutoInsertSpaces() および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.