26 if (
main ==
nullptr )
27 throw AtlasException(
"Tried to run executeOnMain without setting a main thread first!" );
29 if ( QThread::currentThread() ==
mainThread() )
32 return func( std::forward< Args >( args )... );
36 if constexpr ( std::same_as< FunctionReturn< Function >,
void > )
39 QMetaObject::invokeMethod(
41 [ func = std::forward< Function >( func ), args... ]() mutable ->
void
45 func( std::forward< Args >( args )... );
52 Qt::QueuedConnection );
57 auto promise { std::make_shared< QPromise< FunctionReturn< Function > > >() };
59 QMetaObject::invokeMethod(
61 [ promise, func, args... ]() ->
void
63 promise->addResult( func( std::forward< Args >( args )... ) );
66 Qt::QueuedConnection );
68 auto future { promise->future() };
69 future.waitForFinished();
70 return future.result();
int main(int argc, char **argv)
Definition main.cpp:39