-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyworkthread.cpp
More file actions
executable file
·91 lines (75 loc) · 2.24 KB
/
myworkthread.cpp
File metadata and controls
executable file
·91 lines (75 loc) · 2.24 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
#include "myworkthread.h"
#include <QEventLoop>
#include <QCoreApplication>
#include <QProgressBar>
#include <QDir>
#include <QDirIterator>
#include <QDebug>
#include <QImage>
myWorkThread::myWorkThread(QString& path)
: m_path(path)
{
}
myWorkThread::~myWorkThread()
{
}
void myWorkThread::run()
{
qDebug() << "thread run in." << " at thread: " << QThread::currentThreadId();
QDir targetDir(m_path);
if (!targetDir.exists())
{
qDebug() << "ERR: in thread, path dir not exist.";
qDebug() << "thread run out.";
return;
}
QStringList nameFilters;
nameFilters << QString("*.jpeg")
<< QString("*.jpg")
<< QString("*.png")
<< QString("*.bmp");
int iAllFileNum = 0;
QDirIterator dirIteratorCount(m_path, nameFilters, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
while(dirIteratorCount.hasNext())
{
dirIteratorCount.next();
iAllFileNum++;
}
if (0 == iAllFileNum)
{
qWarning() << "WAN: in thread, the number of need conver file is zero.";
qWarning() << "thread run out.";
return;
}
QDirIterator dirIteratorConv(m_path, nameFilters, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
QImage qImage;
QString abFilePath("");
int iDoneNum = 0;
emit reportDegree(0);
while(dirIteratorConv.hasNext())
{
do
{
dirIteratorConv.next();
abFilePath = dirIteratorConv.fileInfo().absoluteFilePath();
if (!qImage.load(abFilePath))
{
qDebug() << "ERR: QImage load file failed[" << abFilePath << "].";
break;
}
if (!qImage.save(abFilePath))
{
qDebug() << "ERR: QImage conv file failed[" << abFilePath << "].";
}
else
{
qInfo() << "SESS: conv ok[" << abFilePath << "]";
}
}while(0);
msleep(10);
iDoneNum++;
emit reportDegree((int)((iDoneNum * 100.0f) / (iAllFileNum * 1.0f)));
}
emit reportDegree(100);
qDebug() << "thread run out.";
}