mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Add AsyncTask
This commit is contained in:
parent
49dabaab71
commit
790dd4868e
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
23
src/utils/AsyncTask.cpp
Normal 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
37
src/utils/AsyncTask.h
Normal 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
|
Loading…
Reference in New Issue
Block a user