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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user