UI: Add way to exec std::function via invokeMethod

Allows the ability to use invokeMethod on the OBSApp object to execute
an std::function.  This allows deferring an std::function call to the Qt
event queue.
This commit is contained in:
jp9000 2019-03-05 14:34:40 -08:00
parent d8812e0808
commit 106222154a
2 changed files with 15 additions and 0 deletions

View file

@ -1241,12 +1241,21 @@ void OBSApp::EnableInFocusHotkeys(bool enable)
ResetHotkeyState(applicationState() != Qt::ApplicationActive);
}
Q_DECLARE_METATYPE(VoidFunc)
void OBSApp::Exec(VoidFunc func)
{
func();
}
bool OBSApp::OBSInit()
{
ProfileScope("OBSApp::OBSInit");
setAttribute(Qt::AA_UseHighDpiPixmaps);
qRegisterMetaType<VoidFunc>();
if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
return false;

View file

@ -26,6 +26,7 @@
#include <util/util.hpp>
#include <util/platform.h>
#include <obs-frontend-api.h>
#include <functional>
#include <string>
#include <memory>
#include <vector>
@ -58,6 +59,8 @@ public:
const char *disambiguation, int n) const override;
};
typedef std::function<void ()> VoidFunc;
class OBSApp : public QApplication {
Q_OBJECT
@ -166,6 +169,9 @@ public:
translatorHooks.pop_front();
}
public slots:
void Exec(VoidFunc func);
signals:
void StyleChanged();
};