QDebug Class

QDebug クラスは、デバッグ情報の出力ストリームを提供します。詳細...

ヘッダ #include <QDebug>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
を継承する: QIODeviceBase
継承される

QQmlInfo

パブリック・タイプ

enum VerbosityLevel { MinimumVerbosity, DefaultVerbosity, MaximumVerbosity }

パブリック関数

QDebug(QIODevice *device)
QDebug(QString *string)
QDebug(QtMsgType t)
QDebug(const QDebug &o)
~QDebug()
bool autoInsertSpaces() const
QDebug &maybeQuote(char c = '"')
QDebug &maybeSpace()
QDebug &noquote()
QDebug &nospace()
QDebug &quote()
(since 6.7) bool quoteStrings() const
QDebug &resetFormat()
void setAutoInsertSpaces(bool b)
(since 6.7) void setQuoteStrings(bool b)
void setVerbosity(int verbosityLevel)
QDebug &space()
void swap(QDebug &other)
int verbosity() const
QDebug &verbosity(int verbosityLevel)
(since 6.0) QDebug &operator<<(QByteArrayView t)
QDebug &operator<<(QChar t)
QDebug &operator<<(QLatin1StringView t)
QDebug &operator<<(QStringView s)
(since 6.0) QDebug &operator<<(QUtf8StringView s)
(since 6.7) QDebug &operator<<(T i)
(since 6.7) QDebug &operator<<(T i)
QDebug &operator<<(bool t)
QDebug &operator<<(char t)
QDebug &operator<<(char16_t t)
QDebug &operator<<(char32_t t)
QDebug &operator<<(const QByteArray &t)
QDebug &operator<<(const QString &t)
QDebug &operator<<(const char *t)
(since 6.0) QDebug &operator<<(const char16_t *t)
(since 6.5) QDebug &operator<<(const std::basic_string<Char, Args...> &s)
QDebug &operator<<(const void *t)
QDebug &operator<<(double t)
QDebug &operator<<(float t)
QDebug &operator<<(int t)
QDebug &operator<<(long t)
QDebug &operator<<(qint64 t)
QDebug &operator<<(quint64 t)
QDebug &operator<<(short t)
(since 6.5) QDebug &operator<<(std::basic_string_view<Char, Args...> s)
(since 6.6) QDebug &operator<<(std::chrono::duration<Rep, Period> duration)
(since 6.7) QDebug &operator<<(std::nullopt_t)
QDebug &operator<<(unsigned int t)
QDebug &operator<<(unsigned long t)
QDebug &operator<<(unsigned short t)
QDebug &operator=(const QDebug &other)

静的パブリックメンバ

(since 6.0) QString toString(const T &object)
QDebug operator<<(QDebug debug, const QHash<Key, T> &hash)
QDebug operator<<(QDebug debug, const QList<T> &list)
QDebug operator<<(QDebug debug, const QMap<Key, T> &map)
QDebug operator<<(QDebug debug, const QMultiHash<Key, T> &hash)
QDebug operator<<(QDebug debug, const QMultiMap<Key, T> &map)
QDebug operator<<(QDebug debug, const QSet<T> &set)
(since 6.3) QDebug operator<<(QDebug debug, const QVarLengthArray<T, P> &array)
QDebug operator<<(QDebug debug, const std::list<T, Alloc> &vec)
QDebug operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map)
QDebug operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map)
QDebug operator<<(QDebug debug, const std::pair<T1, T2> &pair)
QDebug operator<<(QDebug debug, const std::vector<T, Alloc> &vec)
QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)
QDebug operator<<(QDebug debug, const QFlags<T> &flags)

詳細説明

QDebug は、開発者がデバッグまたはトレース情報をデバイス、ファイル、文字列、またはコンソールに書き出す必要がある場合に使用します。

基本的な使い方

一般的なケースでは、qDebug() 関数を呼び出して、デバッグ情報の書き込みに使用するデフォルトの QDebug オブジェクトを取得するのが便利です。

   qDebug()<< "日付:"<<QDate::currentDate();    qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40);
    qDebug() << "Custom coordinate type:" << coordinate;

QtMsgType QtDebugMsg同様に、qWarning()、qCritical()、qFatal() 関数も、対応するメッセージ・タイプの QDebug オブジェクトを返します。

このクラスには、QFile や、ファイルやその他のデバイスにデバッグ情報を書き込むために使用されるその他のQIODevice サブクラスを受け付けるコンストラクタなど、その他の状況に対応するコンストラクタもいくつか用意されています。QString を受け付けるコンストラクタは、表示やシリアライズのために文字列に書き込むために使用されます。

フォーマット・オプション

QDebug は出力を読みやすいようにフォーマットします。QDebugは自動的に引数の間にスペースを追加し、QString,QByteArray,QChar の引数の周りに引用符を追加します。

これらのオプションは、space(),nospace() とquote(),noquote() メソッドで調整できます。さらに、QTextStream manipulators を QDebug ストリームにパイプすることもできます。

QDebugStateSaver は、書式の変更を現在のスコープに制限します。() はオプションをデフォルトのものにリセットします。resetFormat

ストリームへのカスタム型の書き込み

多くの標準型は QDebug オブジェクトに書き込むことができ、Qt はほとんどの Qt 値型をサポートしています。カスタム型のサポートを追加するには、以下の例のようにストリーミング演算子を実装する必要があります:

QDebug operator<<(QDebug debug, const Coordinate &c)
{
    QDebugStateSaver saver(debug);
    debug.nospace() << '(' << c.x() << ", " << c.y() << ')';

    return debug;
}

これについては、「デバッグ技法」と「カスタム Qt 型の作成」で説明しています。

メンバ型のドキュメント

enum QDebug::VerbosityLevel

この列挙型は、冗長性レベルの範囲を記述する。

定数
QDebug::MinimumVerbosity0
QDebug::DefaultVerbosity2
QDebug::MaximumVerbosity7

verbosity() およびsetVerbosity()も参照

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

[since 6.5] template <typename Char, typename... Args> QDebug &QDebug::operator<<(const std::basic_string<Char, Args...> &s)

[since 6.5] template <typename Char, typename... Args> QDebug &QDebug::operator<<(std::basic_string_view<Char, Args...> s)

文字列またはストリングビューs をストリームに書き込み、ストリームへの参照を返します。

これらの演算子は、Char

  • char
  • char8_t (C++20 のみ)
  • char16_t
  • char32_t
  • wchar_t

この関数はQt 6.5で導入されました。

[since 6.7] template <typename T, QDebug::if_qint128<T> = true> QDebug &QDebug::operator<<(T i)

[since 6.7] template <typename T, QDebug::if_quint128<T> = true> QDebug &QDebug::operator<<(T i)

128 ビット整数i のテキスト表現を表示します。

注意: この演算子はQtが128ビット整数型をサポートしている場合にのみ使用できます。ビルド時に128ビット整数型が使用可能で、Qtライブラリが使用されずにコンパイルされた場合、この演算子は代わりに警告を表示します。

注意: 演算子は関数テンプレートなので、引数に対して暗黙の変換は行われません。正確に qint128/quint128 でなければなりません。

この関数はQt 6.7で導入されました。

QT_SUPPORTS_INT128も参照してください

[explicit] QDebug::QDebug(QIODevice *device)

与えられたdevice に書き込むデバッグストリームを構築する。

[explicit] QDebug::QDebug(QString *string)

与えられたstring に書き込むデバッグストリームを構築する。

[explicit] QDebug::QDebug(QtMsgType t)

メッセージタイプt のハンドラに書き込むデバッグストリームを構築する。

QDebug::QDebug(const QDebug &o)

もう一方のデバッグ・ストリームのコピーを作成するo

[noexcept] QDebug::~QDebug()

書き込むべき保留中のデータをすべてフラッシュし、デバッグ・ストリームを破棄する。

bool QDebug::autoInsertSpaces() const

このQDebug インスタンスが書き込みの間にスペースを自動的に挿入する場合はtrue を返す。

setAutoInsertSpaces() およびQDebugStateSaverも参照

QDebug &QDebug::maybeQuote(char c = '"')

引用符の自動挿入の現在の設定に応じて、デバッグストリームに文字c を書き込み、ストリームへの参照を返す。

デフォルトの文字は二重引用符" です。

quote() およびnoquote()も参照

QDebug &QDebug::maybeSpace()

空白文字の自動挿入の現在の設定に応じて、空白文字をデバッグストリームに書き込み、ストリームへの参照を返す。

space() およびnospace()も参照

QDebug &QDebug::noquote()

QCharQStringQByteArray の内容の周囲への引用文字の自動挿入を無効にし、ストリームへの参照を返す。

引用符で囲むことを無効にすると、これらの型は引用符なしで印刷され、印刷不可能な文字もエスケープされない。

quote() およびmaybeQuote()も参照のこと

QDebug &QDebug::nospace()

空白の自動挿入を無効にし、ストリームへの参照を返します。

space() およびmaybeSpace()も参照

QDebug &QDebug::quote()

QCharQStringQByteArray の内容の周囲に引用符を自動的に挿入できるようにし、ストリームへの参照を返す。

デフォルトでは、引用は有効になっています。

noquote() およびmaybeQuote()も参照

[noexcept, since 6.7] bool QDebug::quoteStrings() const

このQDebug インスタンスがストリームされた文字列を引用する場合(デフォルト)、true を返します。

この関数は Qt 6.7 で導入されました。

QDebugStateSaver,quote(),noquote(),setQuoteStrings()も参照してください

QDebug &QDebug::resetFormat()

ストリームのフォーマットオプションをリセットし、元の構築状態に戻します。

space() およびquote()も参照

void QDebug::setAutoInsertSpaces(bool b)

b が真の場合、書き込みの間に空白を自動挿入する。そうでない場合、空白の自動挿入は無効になる。

autoInsertSpaces() およびQDebugStateSaverも参照のこと

[since 6.7] void QDebug::setQuoteStrings(bool b)

btrue の場合、このQDebug インスタンスにストリーミ ングされる文字列のクォートを有効にする。

デフォルトは文字列の引用です。

この関数は Qt 6.7 で導入されました。

QDebugStateSaver,quote(),noquote(),quoteStrings()も参照してください

void QDebug::setVerbosity(int verbosityLevel)

ストリームの冗長度をverbosityLevel に設定します。

許容範囲は 0 から 7 である。デフォルト値は2である。

verbosity() およびVerbosityLevelも参照

QDebug &QDebug::space()

スペース文字をデバッグストリームに書き込み、ストリームへの参照を返す。

ストリームは、今後の書き込みで空白文字の自動挿入が有効になっていることを記憶しています。

nospace() およびmaybeSpace()も参照

[noexcept] void QDebug::swap(QDebug &other)

このデバッグ・ストリームのインスタンスをother と交換する。この操作は非常に高速で、失敗することはない。

[static, since 6.0] template <typename T> QString QDebug::toString(const T &object)

文字列を操作するQDebug インスタンスにobject をストリームし、その文字列を返す。

この関数は、デバッグのためにオブジェクトのテキスト表現が必要だが、operator<< を使用できない場合に便利です。例えば

    QTRY_VERIFY2(list.isEmpty(), qPrintable(QString::fromLatin1(
        "Expected list to be empty, but it has the following items: %1")).arg(QDebug::toString(list)));

文字列はnospace() を使ってストリームされます。

この関数は Qt 6.0 で導入されました。

int QDebug::verbosity() const

デバッグストリームの冗長度を返します。

ストリーミングオペレータはこの値をチェックして、冗長な出力が必要かどうかを判断し、レベルに応じてより多くの情報を出力することができます。値が大きいほど、より多くの情報が必要であることを示す。

許容範囲は0から7までです。デフォルト値は2である。

setVerbosity() およびVerbosityLevelも参照のこと

QDebug &QDebug::verbosity(int verbosityLevel)

ストリームの冗長度をverbosityLevel に設定し、ストリームへの参照を返します。

許容範囲は 0 から 7 です。デフォルト値は2である。

verbosity()、setVerbosity()、VerbosityLevelも参照

[since 6.0] QDebug &QDebug::operator<<(QByteArrayView t)

観測されたバイト配列t のデータをストリームに書き込み、ストリームへの参照を返します。

通常、QDebug はデータを引用符で囲んで出力し、制御文字や非 US-ASCII 文字を C のエスケープ・シーケンス( \xAB )に変換します。こうすることで、出力は常に 7 ビットのクリーンな状態になり、必要に応じて出力から文字列をコピーして C++ ソースに貼り付けることができます。

印字不可能な文字を変換せずに出力するには、noquote() 機能を有効にします。QDebug バックエンドによっては、8ビット・クリーンにならない場合があることに注意。

例についてはQByteArray オーバーロードを参照してください。

この関数は Qt 6.0 で導入されました。

QDebug &QDebug::operator<<(QChar t)

t という文字をストリームに書き込み、ストリームへの参照を返します。通常、QDebug は制御文字と非 US-ASCII 文字を C エスケープ・シーケンスまたは Unicode 値 ( \u1234) として出力します。非印刷文字を変換なしで印刷するには、noquote() 機能を有効にします。ただし、QDebug バックエンドの中には 8 ビットクリーンでないものがあり、t を表現できない場合があることに注意してください。

QDebug &QDebug::operator<<(QLatin1StringView t)

文字列t をストリームに書き込み、ストリームへの参照を返します。通常、QDebug は文字列を引用符で囲んで印刷し、印刷不可能な文字を Unicode 値 ( \u1234) に変換します。

印刷不可能な文字を変換せずに印刷するには、noquote() 機能を有効にします。QDebug バックエンドの中には 8 ビット・クリーンでないものがあることに注意してください。

例についてはQString オーバーロードを参照してください。

QDebug &QDebug::operator<<(QStringView s)

文字列ビューs をストリームに書き込み、ストリームへの参照を返します。通常、QDebug は文字列を引用符で囲んで表示し、印刷不可能な文字を Unicode 値 ( \u1234) に変換します。

印刷不可能な文字を変換せずに印刷するには、noquote() 機能を有効にします。QDebug バックエンドの中には 8 ビット・クリーンでないものがあることに注意してください。

例についてはQString オーバーロードを参照してください。

[since 6.0] QDebug &QDebug::operator<<(QUtf8StringView s)

文字列ビューs をストリームに書き込み、ストリームへの参照を返します。

通常、QDebug はデータを引用符で囲んで出力し、制御文字や非 US-ASCII 文字を C のエスケープ・シーケンス( \xAB )に変換します。こうすることで、出力は常に 7 ビットのクリーンな状態になり、必要に応じて出力から文字列をコピーして C++ ソースに貼り付けることができます。

印字不可能な文字を変換せずに出力するには、noquote() 機能を有効にします。QDebug バックエンドによっては、8ビットクリーンでない場合があることに注意してください。

この関数は Qt 6.0 で導入されました。

QDebug &QDebug::operator<<(bool t)

ブール値t をストリームに書き込み、ストリームへの参照を返します。

QDebug &QDebug::operator<<(char t)

文字t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(char16_t t)

UTF-16 文字t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(char32_t t)

UTF-32 文字t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(const QByteArray &t)

バイト配列t をストリームに書き込み、ストリームへの参照を返します。通常、QDebug は配列を引用符で囲んで出力し、制御文字や非 US-ASCII 文字を C のエスケープ・シーケンス( \xAB )に変換します。こうすることで、出力は常に7ビットのクリーンな状態になり、必要に応じて出力から文字列をコピーしてC++ソースに貼り付けることができます。

印字不可能な文字を変換せずに出力するには、noquote() 機能を有効にします。QDebug バックエンドによっては、8ビット・クリーンにならない場合があることに注意。

出力例:

    QByteArrayba; ba= "a"qDebug().noquote() << ba;    // prints: a
    qDebug() << ba;              // prints: "a"

    ba= "꒰"꒱"꒱"qDebug() << ba;              // prints: "\"a\r\n\""

    ba= "\033";// エスケープ文字    qDebug() << ba;              // prints: "\x1B"

    ba= " \xC3xA1"qDebug() << ba;              // prints: "\xC3\xA1"

    ba=QByteArray("a0b", 3);    qDebug() << ba               // prints: "\a\x00""b"

文字'b'が直前の16進エスケープ・シーケンスの一部として解釈されないように、C言語とC++言語が文字列リテラルを連結する方法で、QDebug 、文字列を閉じて開き直す必要があったことに注意してほしい。

QDebug &QDebug::operator<<(const QString &t)

文字列t をストリームに書き込み、ストリームへの参照を返します。通常、QDebug は文字列を引用符で囲んで印刷し、印刷不可能な文字を Unicode 値 ( \u1234) に変換します。

印刷不可能な文字を変換せずに印刷するには、noquote() 機能を有効にします。QDebug バックエンドの中には 8 ビット・クリーンでないものがあることに注意してください。

出力例:

    QStrings; s= "a"qDebug().noquote() << s;    // prints: a
    qDebug() << s;              // prints: "a"

    s= "\"aArika    qDebug() << s;              // prints: "\"a\r\n\""

    s= "\033";// エスケープ文字    qDebug() << s;              // prints: "\u001B"

    s= "\u00AD";// ソフトハイフン    qDebug() << s;              // prints: "\u00AD"

    s= "\u00E1";// ラテン小文字 A WITH ACUTE    qDebug() << s;              // prints: "á"

    s= "au0301";// "a "の後にコンバイニング・アキュート・アクセントが続く    qDebug() << s;              // prints: "á";

    s= " \u0430u0301";// CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT    qDebug() << s;              // prints: "а́"

QDebug &QDebug::operator<<(const char *t)

'¥0'終端の UTF-8 文字列t をストリームに書き込み、ストリームへの参照を返します。文字列は、引用符で囲まれたり、エスケープされて出力されることはありません。QDebug 、内部的にはUTF-16としてバッファリングされ、バックエンドによってはロケールのコーデックを使って8ビットに変換する必要があり、出力が文字化けする可能性があることに注意(mojibake)。US-ASCII文字列に制限することを推奨します。

[since 6.0] QDebug &QDebug::operator<<(const char16_t *t)

u' \0'- 終了 UTF-16 文字列t をストリームに書き込み、ストリームへの参照を返します。文字列は、引用符で囲んだり、エスケープして出力されることはありません。QDebug は内部的にUTF-16としてバッファリングされ、バックエンドによってはロケールのコーデックを使って8ビットに変換する必要があり、出力が文字化けする可能性があることに注意してください(mojibake)。US-ASCII文字列に制限することを推奨します。

この関数は Qt 6.0 で導入されました。

QDebug &QDebug::operator<<(const void *t)

ポインタt をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(double t)

64 ビット浮動小数点数t をストリームに書き込み、ストリームへの参照を返します。

QDebug &QDebug::operator<<(float t)

32 ビット浮動小数点数t をストリームに書き込み、ストリームへの参照を返します。

QDebug &QDebug::operator<<(int t)

符号付き整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(long t)

符号付き長整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(qint64 t)

符号付き 64 ビット整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(quint64 t)

符号なし 64 ビット整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(short t)

符号付き短整数t をストリームに書き込み、ストリームへの参照を返します。

[since 6.6] template <typename Rep, typename Period> QDebug &QDebug::operator<<(std::chrono::duration<Rep, Period> duration)

duration をストリームに出力し、ストリームへの参照を返します。出力される文字列は、C++標準ライブラリがstd::ostream で生成するものと同様に、期間の数値表現とそれに続く時間単位です。

単位はローカライズされません。

この関数は Qt 6.6 で導入されました。

[since 6.7] QDebug &QDebug::operator<<(std::nullopt_t)

nullopt をストリームに書き込みます。

この関数は Qt 6.7 で導入されました。

QDebug &QDebug::operator<<(unsigned int t)

符号なし整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(unsigned long t)

符号なし長整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator<<(unsigned short t)

符号なし短整数t をストリームに書き込み、ストリームへの参照を返す。

QDebug &QDebug::operator=(const QDebug &other)

other デバッグストリームをこのストリームに割り当て、このストリームへの参照を返します。

関連する非会員

template <typename Key, typename T> QDebug operator<<(QDebug debug, const QHash<Key, T> &hash)

hash の内容をdebug に書き込む。KeyT の両方がQDebug へのストリーミングをサポートする必要がある。

template <typename T> QDebug operator<<(QDebug debug, const QList<T> &list)

list の内容をdebug に書き込む。TQDebug へのストリーミングをサポートする必要がある。

template <typename Key, typename T> QDebug operator<<(QDebug debug, const QMap<Key, T> &map)

map の内容をdebug に書き込む。KeyT の両方が、QDebug へのストリーミングをサポートする必要がある。

template <typename Key, typename T> QDebug operator<<(QDebug debug, const QMultiHash<Key, T> &hash)

hash の内容をdebug に書き込む。KeyT の両方が、QDebug へのストリーミングをサポートする必要がある。

template <typename Key, typename T> QDebug operator<<(QDebug debug, const QMultiMap<Key, T> &map)

map の内容をdebug に書き込む。KeyT の両方がQDebug へのストリーミングをサポートする必要がある。

template <typename T> QDebug operator<<(QDebug debug, const QSet<T> &set)

set の内容をdebug に書き込む。TQDebug へのストリーミングをサポートする必要がある。

[since 6.3] template <typename T, qsizetype P> QDebug operator<<(QDebug debug, const QVarLengthArray<T, P> &array)

array の内容をdebug に書き込みます。TQDebug へのストリーミングをサポートする必要があります。

この関数は Qt 6.3 で導入されました。

template <typename T, typename Alloc> QDebug operator<<(QDebug debug, const std::list<T, Alloc> &vec)

リストvec の内容をdebug に書き込む。TQDebug へのストリーミングをサポートする必要がある。

template <typename Key, typename T, typename Compare, typename Alloc> QDebug operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map)

map の内容をdebug に書き込む。KeyT の両方がQDebug へのストリーミングをサポートする必要がある。

template <typename Key, typename T, typename Compare, typename Alloc> QDebug operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map)

map の内容をdebug に書き込む。KeyT の両方がQDebug へのストリーミングをサポートする必要がある。

template <typename T1, typename T2> QDebug operator<<(QDebug debug, const std::pair<T1, T2> &pair)

pair の内容をdebug に書き込む。T1T2 の両方がQDebug へのストリーミングをサポートする必要がある。

template <typename T, typename Alloc> QDebug operator<<(QDebug debug, const std::vector<T, Alloc> &vec)

ベクトルvec の内容をdebug に書き込む。TQDebug へのストリーミングをサポートする必要がある。

template <typename T> QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)

cache の内容をdebug に書き込む。TQDebug へのストリーミングをサポートする必要がある。

template <typename T> QDebug operator<<(QDebug debug, const QFlags<T> &flags)

debugflags を書き込む。

© 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.