Using update.h/.cpp and thread pool
This commit is contained in:
parent
892fae92ad
commit
6d4c247de7
17
main.cpp
17
main.cpp
@ -16,7 +16,7 @@
|
|||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "update.h"
|
||||||
|
|
||||||
#ifdef PTU5
|
#ifdef PTU5
|
||||||
#define SERIAL_PORT "ttymxc2"
|
#define SERIAL_PORT "ttymxc2"
|
||||||
@ -25,11 +25,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Work : public QRunnable {
|
class Work : public QRunnable {
|
||||||
Utils m_utils;
|
QString m_update_ctrl_file;
|
||||||
public:
|
public:
|
||||||
explicit Work(QString update_ctrl_file) : m_utils(update_ctrl_file) {}
|
explicit Work(QString update_ctrl_file)
|
||||||
|
: m_update_ctrl_file(update_ctrl_file) {}
|
||||||
void run() {
|
void run() {
|
||||||
m_utils.doUpdate();
|
Update m_update(m_update_ctrl_file);
|
||||||
|
m_update.doUpdate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,11 +49,14 @@ int main(int argc, char *argv[]) {
|
|||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
update_ctrl_file = argv[1];
|
update_ctrl_file = argv[1];
|
||||||
}
|
}
|
||||||
qCritical() << "Using" << update_ctrl_file << "as update logfile";
|
qInfo() << "Using" << update_ctrl_file << "as update logfile";
|
||||||
|
|
||||||
Work work(update_ctrl_file);
|
Work work(update_ctrl_file);
|
||||||
work.setAutoDelete(false);
|
work.setAutoDelete(false);
|
||||||
QThreadPool *threadPool = QThreadPool::globalInstance();
|
QThreadPool *threadPool = QThreadPool::globalInstance();
|
||||||
threadPool->start(&work);
|
threadPool->start(&work);
|
||||||
return threadPool->waitForDone();
|
if (!threadPool->waitForDone()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user