Commit 32495f55 authored by hjk's avatar hjk
Browse files

more fixes to the example

parent 13dec817
......@@ -573,51 +573,36 @@
\c{textfinder.cpp}. We begin by filling in the functionality to load a
text file. The code snippet below describes this:
void TextFinder::loadTextFile()
QFile inputFile(":/input.txt");;
QTextStream in(&inputFile);
QString line = in.readAll();
QTextCursor cursor = ui->textEdit->textCursor();
\quotefromfile textfinder.cpp
\skipto TextFinder::loadTextFile
\printuntil }
Basically, we load a text file using
\l{}{QFile}, read it with
\l{}{QTextStream}, and
then display it on \c{textEdit} with
which requires adding the following additional #includes to textfinder.cpp:
#include <QtCore/QFile>
#include <QtCore/QTextStream>
For the \c{on_findButton_clicked()} slot, we extract the search string and
use the \l{}{find()} function
to look for the search string within the text file. The code snippet below
further describes it:
void TextFinder::on_findButton_clicked()
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
\quotefromfile textfinder.cpp
\skipto on_findButton_clicked
\printuntil }
Once we have both these functions complete, we call \c{loadTextFile()} in
our constructor.
TextFinder::TextFinder(QWidget *parent)
: QWidget(parent)
\quotefromfile textfinder.cpp
\skipto TextFinder::TextFinder
\printuntil }
The \c{on_findButton_clicked()} slot will be called automatically due to
this line of code:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment