西工大的学弟学妹们,加油吧,QT版全部答案,仅供参考
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->lineEdit->setFocus();
}
Widget::~Widget()
{
delete ui;
}
void Widget::loadTextFile(QString i){
QString st1,st2;
st1 = ":/res/";
st2 = i + ".txt";
st1 += st2;
QFile inputFile(st1);
inputFile.open(QIODevice::ReadOnly);
QTextStream in(&inputFile);
QString line = in.readAll();
inputFile.close();
ui->textEdit->setPlainText(line);
ui->lineEdit_2->setFocus();
// QTextCursor cursor = ui->textEdit->textCursor();
//cursor.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor,1);
}
void Widget::on_pushButton_4_clicked()
{
QString st;
st = ui->lineEdit->text();
if(st.toInt()>7||st.toInt()lineEdit->selectAll();
ui->lineEdit->setFocus();
}
else
loadTextFile(st);
}
void Widget::on_pushButton_2_clicked()
{
QString searchString = ui->lineEdit_2->text();
QString aimedStr = ui->textEdit->toPlainText();
if(aimedStr == "")
{
QMessageBox::warning(this, tr("Search String"),
tr("Please select text"),
QMessageBox::Ok);
ui->lineEdit->selectAll();
ui->lineEdit->setFocus();
}
else{
if(searchString == "")
{
QMessageBox::warning(this, tr("Search String"),
tr("Please enter a search string"),
QMessageBox::Ok);
ui->lineEdit_2->setFocus();
}
else{
1