PDA

View Full Version : newbies here--the Qt tutorial textfinder does not work.



fenghe
20th January 2015, 03:47
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) :
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);
}

fenghe
20th January 2015, 06:38
I think I find the problem. The resource should include both .ui and .txt files.