ADTF  3.18.4
task_event.h
Go to the documentation of this file.
1 
8 /*
9  * This file depends on Qt which is licensed under LGPLv3.
10  * See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
11  */
12 
13 #pragma once
14 
15 #include <functional>
16 
17 #include <QEvent>
18 
19 class cTaskEvent : public QEvent
20 {
21  public:
22  cTaskEvent(std::function<void()> oFunc) :
23  QEvent(type()),
24  m_oFunc(oFunc)
25  {}
26 
30  static QEvent::Type type()
31  {
32  if (m_pCustomEventType.get() == nullptr)
33  {
34  const auto oGeneratedType = QEvent::registerEventType();
35  m_pCustomEventType.reset(new QEvent::Type(static_cast<QEvent::Type>(oGeneratedType)));
36  }
37  return *m_pCustomEventType;
38  }
39 
40  void execute()
41  {
42  m_oFunc();
43  }
44 
45  private:
46  static inline std::unique_ptr<QEvent::Type> m_pCustomEventType;
47 
51  std::function<void()> m_oFunc;
52 };
std::function< void()> m_oFunc
std::function which is executed.
Definition: task_event.h:51
static QEvent::Type type()
Register dynamically event type.
Definition: task_event.h:30