FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runner_qthread.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "base_runner.h"
19 
20 #include <QtCore/QThread>
21 #include <QtCore/QTimer>
22 
23 namespace qttask {
24 
27 template<>
28 class Runner<QThread> : public QThread, public BaseRunner
29 {
30 public:
31  Runner<QThread>(const Manager* mgr, QThread::Priority priority = QThread::InheritPriority)
32  : QThread(nullptr),
33  BaseRunner(mgr),
34  m_priority(priority)
35  {
36  }
37 
38 protected:
39  bool isAbortRequested() override
40  { return this->isInterruptionRequested(); }
41 
42  void requestAbort() override
43  { this->requestInterruption(); }
44 
45  void launch() override
46  { this->start(m_priority); }
47 
48  void destroy() override
49  { this->deleteLater(); }
50 
51  void run() override // -- QThread
52  {
53  QTimer::singleShot(0, [=] {
54  this->execRunnableFunc();
55  this->quit();
56  } );
57 
58  this->exec();
59  }
60 
61 private:
62  QThread::Priority m_priority;
63 };
64 
65 } // namespace qttask
Base class for all runner objects.
Definition: base_runner.h:31
BaseRunner(const Manager *mgr)
Definition: base_runner.cpp:22
Definition: base_runner.h:73
void destroy() override
Definition: runner_qthread.h:48
void requestAbort() override
Definition: runner_qthread.h:42
void run() override
Definition: runner_qthread.h:51
Central class providing management of tasks and notifications.
Definition: manager.h:32
Task runner based on QThread.
Definition: runner_qthread.h:28
void execRunnableFunc()
Definition: base_runner.cpp:71
Definition: base_runner.cpp:20
bool isAbortRequested() override
Definition: runner_qthread.h:39
void launch() override
Definition: runner_qthread.h:45