Browse Source

UI: Add WaitConnection() helper func

A helper function used with QMetaObject::invokeMethod which allows the
ability to use Qt::DirectConnection if on the Qt UI thread, or
Qt::BlockingQueuedConnection if on another thread to ensure that
regardless of what thread the invokeMethod is called from, that it will
wait until the invoked method has been called.
jp9000 7 years ago
parent
commit
e7f2cc384d
1 changed files with 9 additions and 0 deletions
  1. 9 0
      UI/qt-wrappers.hpp

+ 9 - 0
UI/qt-wrappers.hpp

@@ -17,8 +17,10 @@
 
 #pragma once
 
+#include <QApplication>
 #include <QMessageBox>
 #include <QWidget>
+#include <QThread>
 #include <obs.hpp>
 
 #include <memory>
@@ -79,3 +81,10 @@ public:
 };
 
 void DeleteLayout(QLayout *layout);
+
+static inline Qt::ConnectionType WaitConnection()
+{
+	return QThread::currentThread() == qApp->thread()
+		? Qt::DirectConnection
+		: Qt::BlockingQueuedConnection;
+}