]> git.sesse.net Git - nageru/blob - post_to_main_thread.h
Release Nageru 1.7.2.
[nageru] / post_to_main_thread.h
1 #ifndef _POST_TO_MAIN_THREAD_H
2 #define _POST_TO_MAIN_THREAD_H 1
3
4 #include <QApplication>
5 #include <QObject>
6 #include <memory>
7
8 // http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style
9 template<typename F>
10 static inline void post_to_main_thread(F &&fun)
11 {
12         QObject signalSource;
13         QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun));
14 }
15
16 #endif  // !defined(_POST_TO_MAIN_THREAD_H)