チュートリアルC++ デバッグ
このチュートリアルでは、TextFinder の例を使って、Qt C++ アプリケーションをDebug モードでデバッグする方法を説明します。
TextFinder はテキストファイルをQString に読み込み、QTextEdit で表示します。TextFinder クラスを見て、格納されたデータを見るには:
textfinder.cppで、カーソル位置を変更する行の行番号とウィンドウ境界の間をクリックして、ブレークポイントを設定する。
- Debug >Start Debugging >Start Debugging of Startup Project に移動するか、F5 を選択します。
- ブレークポイントに関する情報を表示するには、Breakpoints ビューに移動します。

- ブレークポイントを削除するには、ブレークポイントを右クリックし、Delete Breakpoint を選択します。
- TextFinder クラスの基本クラスとデータ・メンバを表示するには、Locals ビューに移動します。

on_findButton_clicked() 関数を修正して、ドキュメントの最初に戻り、カーソルがドキュメントの最後に当たったら検索を続けるようにします。次のコード・スニペットを追加します:
void TextFinder::on_findButton_clicked() { QString searchString = ui->lineEdit->text(); QTextDocument *document = ui->textEdit->document(); QTextCursor cursor = ui->textEdit->textCursor(); cursor = document->find(searchString, cursor, QTextDocument::FindWholeWords); ui->textEdit->setTextCursor(cursor); bool found = cursor.isNull(); if (!found && previouslyFound) { int ret = QMessageBox::question(this, tr("End of Document"), tr("I have reached the end of the document. Would you like " "me to start searching from the beginning of the document?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (ret == QMessageBox::Yes) { cursor = document->find(searchString, QTextDocument::FindWholeWords); ui->textEdit->setTextCursor(cursor); } else return; } previouslyFound = found; }
しかし、上記のコードをコンパイルして実行すると、ロジックエラーのためにアプリケーションが正しく動作しません。このロジックエラーを見つけるには、次のボタンを使ってコードをステップ スルーしてください:
(Stop Debugger)、
(Step Over)、
(Step Into)、
(Step Out)。
チュートリアル:Qt Widgets アプリケーション、デバッグ、デバッガ、およびデバッガも参照してください 。
Copyright © The Qt Company Ltd. and other contributors. 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.