Commit a4bb415f authored by hjk's avatar hjk

update textfinder example

parent 32495f55
......@@ -33,16 +33,16 @@
#include <QtCore/QTextStream>
#include <QtGui/QMessageBox>
TextFinder::TextFinder(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
TextFinder::TextFinder(QWidget *parent)
: QWidget(parent), ui(new Ui::TextFinder)
{
ui.setupUi(this);
ui->setupUi(this);
loadTextFile();
isFirstTime = true;
}
TextFinder::~TextFinder()
{
delete ui;
}
void TextFinder::loadTextFile()
......@@ -54,20 +54,13 @@ void TextFinder::loadTextFile()
QString line = in.readAll();
inputFile.close();
ui.textEdit->setPlainText(line);
QTextCursor cursor = ui.textEdit->textCursor();
ui->textEdit->setPlainText(line);
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
void TextFinder::on_findButton_clicked()
{
QString searchString = ui.lineEdit->text();
QTextDocument *document = ui.textEdit->document();
bool found = false;
ui.textEdit->find(searchString, QTextDocument::FindWholeWords);
QTextCursor cursor = ui.textEdit->textCursor();
if (!cursor.isNull())
found = true;
QString searchString = ui->lineEdit->text();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}
......@@ -34,29 +34,25 @@
#include <QtGui/QWidget>
class QPushButton;
class QTextEdit;
class QLineEdit;
namespace Ui
{
class TextFinder;
}
class TextFinder : public QWidget
{
Q_OBJECT
public:
TextFinder(QWidget *parent = 0, Qt::WFlags flags = 0);
TextFinder(QWidget *parent = 0);
~TextFinder();
private slots:
void on_findButton_clicked();
private:
Ui::Form ui;
Ui::TextFinder *ui;
void loadTextFile();
QPushButton *ui_findButton;
QTextEdit *ui_textEdit;
QLineEdit *ui_lineEdit;
bool isFirstTime;
};
#endif // TEXTFINDER_H
......@@ -608,7 +608,7 @@
this line of code:
\code
QMetaObject::connectSlotsByName(Form);
QMetaObject::connectSlotsByName(TextFinderClass);
\endcode
in the uic generated \c{ui_textfinder.h} file.
......
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