Add AsyncTask

This commit is contained in:
Florian Märkl 2018-05-26 18:21:23 +02:00
parent 49dabaab71
commit 790dd4868e
5 changed files with 70 additions and 2 deletions

View File

@ -6,6 +6,7 @@
#include "utils/TempConfig.h"
#include "utils/Configuration.h"
#include "utils/AsyncTask.h"
#include "Cutter.h"
#include "sdb.h"
@ -71,6 +72,8 @@ CutterCore::CutterCore(QObject *parent) :
# endif
setConfig("dir.prefix", prefix.absolutePath());
#endif
asyncTaskManager = new AsyncTaskManager(this);
}

View File

@ -44,6 +44,8 @@ typedef ut64 RVA;
*/
#define RVA_INVALID RVA_MAX
class AsyncTaskManager;
class RCoreLocked
{
RCore *core;
@ -528,6 +530,7 @@ private:
QString notes;
RCore *core_;
AsyncTaskManager *asyncTaskManager;
};
class ccClass : public CutterCore

View File

@ -160,7 +160,8 @@ SOURCES += \
utils/JsonTreeItem.cpp \
utils/JsonModel.cpp \
dialogs/VersionInfoDialog.cpp \
widgets/ZignaturesWidget.cpp
widgets/ZignaturesWidget.cpp \
utils/AsyncTask.cpp
HEADERS += \
Cutter.h \
@ -235,7 +236,8 @@ HEADERS += \
utils/JsonTreeItem.h \
utils/JsonModel.h \
dialogs/VersionInfoDialog.h \
widgets/ZignaturesWidget.h
widgets/ZignaturesWidget.h \
utils/AsyncTask.h
FORMS += \
dialogs/AboutDialog.ui \

23
src/utils/AsyncTask.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "AsyncTask.h"
void AsyncTask::run()
{
runTask();
emit finished();
}
AsyncTaskManager::AsyncTaskManager(QObject *parent)
: QObject(parent)
{
threadPool = new QThreadPool(this);
}
AsyncTaskManager::~AsyncTaskManager()
{
}
void AsyncTaskManager::start(AsyncTask *task)
{
threadPool->start(task);
}

37
src/utils/AsyncTask.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef ASYNCTASK_H
#define ASYNCTASK_H
#include <QRunnable>
#include <QThreadPool>
class AsyncTask : public QObject, public QRunnable
{
Q_OBJECT
public:
void run() override final;
virtual void runTask() =0;
signals:
void finished();
};
class AsyncTaskManager : public QObject
{
Q_OBJECT
private:
QThreadPool *threadPool;
public:
explicit AsyncTaskManager(QObject *parent = nullptr);
~AsyncTaskManager();
void start(AsyncTask *task);
};
#endif //ASYNCTASK_H