Hi I am just new to the qt programming, what I did is just the tut of qt textfinder. Now it can be compiled, however there is no text showed in the textedit part, does anybody know what mistakes I make?
Here is the code:
#include "textfinder.h"
#include "ui_textfinder.h"
#include <QFile>
#include <QTextStream>
#include <QWidget>
textfinder
::textfinder(QWidget *parent
) : ui(new Ui::textfinder)
{
ui->setupUi(this);
loadTextFile();
//QMetaObject::connectSlotsByName(this);
}
textfinder::~textfinder()
{
delete ui;
}
void textfinder::loadTextFile()
{
QFile inputFile
(":/input.txt");
inputFile.close();
ui->textEdit->setPlainText(line);
}
void textfinder::on_findButton_clicked()
{
QString searchString
= ui
->lineEdit
->text
();
}
#include "textfinder.h"
#include "ui_textfinder.h"
#include <QFile>
#include <QTextStream>
#include <QWidget>
textfinder::textfinder(QWidget *parent) :
QWidget(parent),
ui(new Ui::textfinder)
{
ui->setupUi(this);
loadTextFile();
//QMetaObject::connectSlotsByName(this);
}
textfinder::~textfinder()
{
delete ui;
}
void textfinder::loadTextFile()
{
QFile inputFile(":/input.txt");
inputFile.open(QIODevice::ReadOnly);
QTextStream in(&inputFile);
QString line = in.readAll();
inputFile.close();
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();
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
}
To copy to clipboard, switch view to plain text mode
Bookmarks