Add helper function for ensuring a function is run in the GUI thread (#4091)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QRunnable>
|
||||
#include <QThreadPool>
|
||||
|
||||
@@ -29,6 +30,19 @@ private:
|
||||
std::function<void()> action_;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
static void runInGuiThread(F &&fun)
|
||||
{
|
||||
if (isGuiThread())
|
||||
{
|
||||
fun();
|
||||
}
|
||||
else
|
||||
{
|
||||
postToThread(fun);
|
||||
}
|
||||
}
|
||||
|
||||
// Taken from
|
||||
// https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style
|
||||
// Qt 5/4 - preferred, has least allocations
|
||||
|
||||
Reference in New Issue
Block a user