튜토리얼: C++ 디버깅
이 자습서에서는 TextFinder 예제를 사용하여 Debug 모드에서 Qt C++ 애플리케이션을 디버깅하는 방법을 설명합니다.
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.