Added some classes from a stackoverflow to utilize Qt's concurrency functions especially cancellable QFuture's
This commit is contained in:
parent
ad3f605ada
commit
99d738ee65
5 changed files with 119 additions and 1 deletions
32
core/TaskExecutor.h
Normal file
32
core/TaskExecutor.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef TASKEXECUTOR_H
|
||||
#define TASKEXECUTOR_H
|
||||
/* From answer by Hatter
|
||||
*
|
||||
* https://stackoverflow.com/questions/5423058/qfuture-that-can-be-cancelled-and-report-progress
|
||||
*/
|
||||
#include "ControllableTask.h"
|
||||
#include "RunControllableTask.h"
|
||||
|
||||
/**
|
||||
* @brief The TaskExecutor class
|
||||
*
|
||||
* The user should sublass ControllableTask, implement background routine which checks sometimes
|
||||
* method shouldRun() of TaskControl instance passed to run(TaskControl&) and then use it like:
|
||||
*
|
||||
* QFututre<int> futureValue = TaskExecutor::run(new SomeControllableTask(inputForThatTask));
|
||||
*
|
||||
* Then she may cancel it by calling futureValue.cancel(), bearing in mind that cancellation is
|
||||
* graceful and not immediate.
|
||||
*
|
||||
*/
|
||||
class TaskExecutor {
|
||||
public:
|
||||
template <class T>
|
||||
static QFuture<T> run(ControllableTask<T>* task) {
|
||||
return (new RunControllableTask<T>(task))->start();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TASKEXECUTOR_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue