-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·100 lines (79 loc) · 1.88 KB
/
mainwindow.cpp
File metadata and controls
executable file
·100 lines (79 loc) · 1.88 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QThread>
#include <QTimer>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
this->currentIndex = 0;
this->sum = 0;
timer = new QTimer(this);
ui->setupUi(this);
ui->radioButton->setChecked(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QFont font;
font.setFamily("Arial");
font.setBold(true);
ui->label->setFont(font);
int sum = ui->textEdit->toPlainText().toInt();
if(sum == this->sum){
ui->label->setText("Success");
} else {
ui->label->setText("Fail");
}
}
void MainWindow::load_number(int num)
{
ui->lcdNumber->display(num);
emit number_loaded(num);
}
void MainWindow::add_loaded_num()
{
if(currentIndex < 4 ){
ui->lcdNumber->display("");
ui->lcdNumber->display(nums.at(currentIndex));
this->sum += nums.at(currentIndex);
this->currentIndex++;
qDebug() << this->sum;
} else{
timer->stop();
}
}
void MainWindow::on_pushButton_2_clicked()
{
timer->start(2000);
connect(timer, SIGNAL(timeout()),this, SLOT(add_loaded_num()));
// connect(this,SIGNAL(number_loaded(int)),ui->lcdNumber,SLOT(display(int)));
}
void MainWindow::readNUmsFromFile()
{
if(file->open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream stream(file);
while (!stream.atEnd()) {
this->nums.append(stream.readLine().toInt());
}
}
}
void MainWindow::on_radioButton_clicked()
{
this->file = new QFile( "1.txt");
readNUmsFromFile();
}
void MainWindow::on_radioButton_2_clicked()
{
this->file = new QFile( "2.txt");
readNUmsFromFile();
}
void MainWindow::on_radioButton_3_clicked()
{
this->file = new QFile( "2.txt");
readNUmsFromFile();
}