Add a utility class/func to allow easy lambda invokes onto GUI thread

This commit is contained in:
baldurk
2015-04-05 17:16:25 +01:00
parent 005d1d0875
commit 19784f6554
2 changed files with 30 additions and 1 deletions
+7
View File
@@ -1,5 +1,7 @@
#include "Core.h"
#include <QTimer>
Core::Core()
{
@@ -10,3 +12,8 @@ Core::~Core()
}
void QInvoke::call(const std::function<void()> &f)
{
QTimer::singleShot(0, new QInvoke(f), SLOT(doInvoke()));
}
+23 -1
View File
@@ -9,10 +9,32 @@ class Core
Core();
~Core();
const RenderManager *Renderer() { return &m_Renderer; }
RenderManager *Renderer() { return &m_Renderer; }
private:
RenderManager m_Renderer;
};
// Utility class for invoking a lambda on the GUI thread.
// This is supported by QTimer::singleShot on Qt 5.4 but it's probably
// wise not to require a higher version that necessary.
#include <functional>
class QInvoke : public QObject
{
Q_OBJECT
QInvoke(const std::function<void()> &f) : func(f) {}
std::function<void()> func;
public:
static void call(const std::function<void()> &f);
protected slots:
void doInvoke()
{
func();
deleteLater();
}
};
#endif // CORE_H