Upute: Debugiranje C++
Ovaj vodič koristi primjer TextFinder-a kako bi ilustrirao otklanjanje pogrešaka Qt C++ aplikacija u načinu rada Debug.
TextFinder čita tekstualnu datoteku u QString i zatim je prikazuje pomoću QTextEdit. Da biste pogledali klasu TextFinder i vidjeli pohranjene podatke:
- U
textfinder.cppu kliknite između broja retka i ruba prozora na retku na kojem mijenjamo položaj kursora kako biste postavili prekidnu točku.
- Idite na Debug > Start Debugging > Start Debugging of Startup Project ili pritisnite F5.
- Za prikaz informacija o prekidnoj točki idite na prikaz Breakpoints.

- Za uklanjanje prekidne točke, kliknite na nju desnom tipkom miša i odaberite Delete Breakpoint.
- Da biste vidjeli osnovne klase i članove podataka klase TextFinder, idite na prikaz Locals.

Mijenjajte funkciju on_findButton_clicked() da se vrati na početak dokumenta i nastavi pretraživanje čim pokazivač stigne do kraja dokumenta. Dodajte sljedeći isječak koda:
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; }
Međutim, ako izvršite kompilaciju i pokrenete gornji kod, aplikacija neće ispravno raditi zbog logičke pogreške. Da biste pronašli ovu logičku pogrešku, korak po korak prođite kroz kod koristeći sljedeća dugmad:
(Stop Debugger),
(Step Over),
(Step Into) i
(Step Out).
Vidi također : Učionica: Primjena Qt Widgets , Otklanjanje pogrešaka i Otklanjači pogrešaka.
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.