-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·83 lines (70 loc) · 2.03 KB
/
mainwindow.cpp
File metadata and controls
executable file
·83 lines (70 loc) · 2.03 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QCoreApplication>
#include "myworkthread.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_myThread(NULL)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
qDebug() << "main window destrorying...";
if (m_myThread)
{
m_myThread->quit();
}
delete ui;
}
void MainWindow::on_pushButton_scan_clicked()
{
QString path = QFileDialog::getExistingDirectory(this, "please the folder to convert", "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (path != "")
{
ui->lineEdit_path->setText(path);
}
}
void MainWindow::on_pushButton_start_convert_clicked()
{
qDebug() << "thread started.";
QString targetPath = ui->lineEdit_path->text();
if (!m_myThread)
{
m_myThread = new myWorkThread(targetPath);
}
connect(m_myThread, SIGNAL(reportDegree(int)), this, SLOT(handleReportDegree(int)), Qt::QueuedConnection);
connect(m_myThread, SIGNAL(finished()), this, SLOT(handleThreadDone()));
m_myThread->start();
qDebug() << "thread working " << " at thread: " << QThread::currentThreadId();
ui->pushButton_start_convert->setEnabled(false);
}
void MainWindow::on_lineEdit_path_textChanged(const QString &arg1)
{
qDebug() << "new path:" << arg1;
if(QDir(arg1).exists())
{
ui->pushButton_start_convert->setEnabled(true);
}
else
{
ui->pushButton_start_convert->setEnabled(false);
}
}
void MainWindow::handleReportDegree(int value)
{
qDebug() << "get degree " << value << " at thread: " << QThread::currentThreadId();
ui->progressBar_convert->setValue(value);
update();
}
void MainWindow::handleThreadDone()
{
qDebug() << "destory the thread.";
m_myThread->quit();
delete(m_myThread);
m_myThread = NULL;
ui->pushButton_start_convert->setEnabled(true);
}