-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
58 lines (45 loc) · 1.09 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
file.setFileName("response.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
qDebug() << "File not opened";
QByteArray line = file.readLine();
ui->source->setText(line);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::checkRegx(QRegExp rx)
{
if (!rx.isValid() && rx.isEmpty() && rx.exactMatch("")){
QMessageBox::information(this, "", "Not valid regx");
return false;
}
else
return true;
}
void MainWindow::on_butFind_clicked()
{
ui->lwResult->clear();
QRegExp rx(ui->regx->text());
if (!checkRegx(rx))
return ;
int pos = 0;
while ((pos = rx.indexIn(ui->source->toPlainText(), pos)) != -1 )
{
QString res = rx.cap(0);
ui->lwResult->addItem(rx.cap(0));
pos += rx.matchedLength();
}
}
void MainWindow::on_butReadLine_clicked()
{
QByteArray line = file.readLine();
ui->source->setText(line);
}