ソースを参照

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.
jp9000 6 年 前
コミット
106222154a
2 ファイル変更15 行追加0 行削除
  1. 9 0
      UI/obs-app.cpp
  2. 6 0
      UI/obs-app.hpp

+ 9 - 0
UI/obs-app.cpp

@@ -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;
 

+ 6 - 0
UI/obs-app.hpp

@@ -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();
 };