「Qtの設定 - デバッグ」の版間の差分

ナビゲーションに移動 検索に移動
87行目: 87行目:
<br>
<br>
<code>qDebug</code>関数は、<code>printf</code>関数と同様の形式で使用できる。<br>
<code>qDebug</code>関数は、<code>printf</code>関数と同様の形式で使用できる。<br>
<syntaxhighlight lang="c++">
#include <QDebug>
  qDebug("test");
  qDebug("test");
  qDebug("int:%d", 10);
  qDebug("int:%d", 10);
  qDebug("double:%lf", 123.45);
  qDebug("double:%lf", 123.45);
  qDebug("string:%s", u8"abcあいう");  
  qDebug("string:%s", u8"abcあいう");
</syntaxhighlight>
<br>
<br>
<code>qDebug</code>関数をC++のストリーム形式で使用する場合、<code>QDebug</code>をインクルードする必要がある。<br>
<code>qDebug</code>関数をC++のストリーム形式で使用する場合、<code>QDebug</code>をインクルードする必要がある。<br>
110行目: 114行目:
  qDebug().nospace() << "double:" << 123.45;
  qDebug().nospace() << "double:" << 123.45;
  qDebug().nospace() << "string:" << u8"abcあいう";
  qDebug().nospace() << "string:" << u8"abcあいう";
</syntaxhighlight>
<br>
<code>QDateTime</code>等のQtの値型の多くのもの、および、<code>QList</code>等のQtのコンテナ型もそのまま出力できる。<br>
<code>QObject</code>クラスの派生型は、<code>QObject</code>のポインタとして出力することにより、クラス名やオブジェクト名と共に出力することができる。<br>
<syntaxhighlight lang="c++">
#include <QDebug>
qDebug() << QString("id=%1, name=%2").arg(123).arg("name_123");  // 出力 : id=123, name=name_123
qDebug() << QDateTime::currentDateTime();                        // 出力 : QDateTime(2020-12-06 21:53:19.311 東京 (標準時) Qt::LocalTime)
QList<double>{1.1, 1.2, 1.3};                                    // 出力 : (1.1, 1.2, 1.3)
QFile file("/etc/fstab");
file.setObjectName("fstab_file");
qDebug() << &file;                                              // 出力 : QFile(0x4a7b6ffb50, name = "fstab_file")
  </syntaxhighlight>
  </syntaxhighlight>
<br><br>
<br><br>

案内メニュー