mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 10:00:40 +00:00
Add a utility class/func to allow easy lambda invokes onto GUI thread
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user