1 #ifndef _POST_TO_MAIN_THREAD_H
2 #define _POST_TO_MAIN_THREAD_H 1
4 #include <QApplication>
9 // http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style
11 static inline void post_to_main_thread(F &&fun)
14 QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun));
18 static inline void post_to_main_thread_and_wait(F &&fun)
20 std::promise<void> done_promise;
21 std::future<void> done = done_promise.get_future();
22 post_to_main_thread(std::move(fun));
23 post_to_main_thread([&done_promise] { done_promise.set_value(); });
27 #endif // !defined(_POST_TO_MAIN_THREAD_H)