Commit 6aeb8a76 authored by hjk's avatar hjk

more fixes to the textfinder example documentation

parent a4bb415f
......@@ -33,18 +33,21 @@
#include <QtCore/QTextStream>
#include <QtGui/QMessageBox>
//! [2]
TextFinder::TextFinder(QWidget *parent)
: QWidget(parent), ui(new Ui::TextFinder)
{
ui->setupUi(this);
loadTextFile();
}
//! [2]
TextFinder::~TextFinder()
{
delete ui;
}
//! [0]
void TextFinder::loadTextFile()
{
QFile inputFile(":/input.txt");
......@@ -58,9 +61,12 @@ void TextFinder::loadTextFile()
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
//! [0]
//! [1]
void TextFinder::on_findButton_clicked()
{
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}
//! [1]
......@@ -565,7 +565,7 @@
void loadTextFile();
\endcode
\note The \c{Ui::Form} object is already provided.
\note The \c{Ui::TextFinder} object is already provided.
\section2 The Source File
......@@ -573,9 +573,7 @@
\c{textfinder.cpp}. We begin by filling in the functionality to load a
text file. The code snippet below describes this:
\quotefromfile textfinder.cpp
\skipto TextFinder::loadTextFile
\printuntil }
\snippet example/textfinder/textfinder.cpp 0
Basically, we load a text file using
\l{http://doc.trolltech.com/qfile.html}{QFile}, read it with
......@@ -593,22 +591,18 @@
to look for the search string within the text file. The code snippet below
further describes it:
\quotefromfile textfinder.cpp
\skipto on_findButton_clicked
\printuntil }
\snippet example/textfinder/textfinder.cpp 1
Once we have both these functions complete, we call \c{loadTextFile()} in
our constructor.
\quotefromfile textfinder.cpp
\skipto TextFinder::TextFinder
\printuntil }
\snippet example/textfinder/textfinder.cpp 2
The \c{on_findButton_clicked()} slot will be called automatically due to
this line of code:
\code
QMetaObject::connectSlotsByName(TextFinderClass);
QMetaObject::connectSlotsByName(TextFinder);
\endcode
in the uic generated \c{ui_textfinder.h} file.
......@@ -1184,13 +1178,13 @@
\code
void TextFinder::on_findButton_clicked()
{
QString searchString = ui.lineEdit->text();
QString searchString = ui->lineEdit->text();
QTextDocument *document = ui.textEdit->document();
QTextCursor cursor = ui.textEdit->textCursor();
QTextDocument *document = ui->textEdit->document();
QTextCursor cursor = ui->textEdit->textCursor();
cursor = document->find(searchString, cursor,
QTextDocument::FindWholeWords);
ui.textEdit->setTextCursor(cursor);
ui->textEdit->setTextCursor(cursor);
bool found = cursor.isNull();
......@@ -1203,7 +1197,7 @@
if (ret == QMessageBox::Yes) {
cursor = document->find(searchString,
QTextDocument::FindWholeWords);
ui.textEdit->setTextCursor(cursor);
ui->textEdit->setTextCursor(cursor);
} else
return;
}
......
......@@ -8,6 +8,7 @@ sourcedirs =
sourcedirs = $SRCDIR
imagedirs = $SRCDIR
outputdir = $OUTDIR
exampledirs = $SRCDIR
extraimages.HTML = qt-logo \
trolltech-logo
......
Markdown is supported
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