mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 04:42:18 +02:00
UI: Add functions for executing funcs without blocking
Adds functions for executing functions within separate threads without blocking the user interface, or by blocking the user interface with a dialog box.
This commit is contained in:
parent
74cda9a2cc
commit
a0eab1a2ad
@ -223,3 +223,43 @@ QThread *CreateQThread(std::function<void()> func)
|
||||
{
|
||||
return new QuickThread(func);
|
||||
}
|
||||
|
||||
void ExecuteFuncSafeBlock(std::function<void()> func)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
|
||||
auto wait = [&] ()
|
||||
{
|
||||
func();
|
||||
QMetaObject::invokeMethod(&eventLoop, "quit",
|
||||
Qt::QueuedConnection);
|
||||
};
|
||||
|
||||
QScopedPointer<QThread> thread(CreateQThread(wait));
|
||||
thread->start();
|
||||
eventLoop.exec();
|
||||
thread->wait();
|
||||
}
|
||||
|
||||
void ExecuteFuncSafeBlockMsgBox(
|
||||
std::function<void()> func,
|
||||
const QString &title,
|
||||
const QString &text)
|
||||
{
|
||||
QMessageBox dlg;
|
||||
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowCloseButtonHint);
|
||||
dlg.setWindowTitle(title);
|
||||
dlg.setText(text);
|
||||
dlg.setStandardButtons(0);
|
||||
|
||||
auto wait = [&] ()
|
||||
{
|
||||
func();
|
||||
QMetaObject::invokeMethod(&dlg, "accept", Qt::QueuedConnection);
|
||||
};
|
||||
|
||||
QScopedPointer<QThread> thread(CreateQThread(wait));
|
||||
thread->start();
|
||||
dlg.exec();
|
||||
thread->wait();
|
||||
}
|
||||
|
@ -67,6 +67,12 @@ QDataStream &operator>>(QDataStream &in, OBSSceneItem &si);
|
||||
|
||||
QThread *CreateQThread(std::function<void()> func);
|
||||
|
||||
void ExecuteFuncSafeBlock(std::function<void()> func);
|
||||
void ExecuteFuncSafeBlockMsgBox(
|
||||
std::function<void()> func,
|
||||
const QString &title,
|
||||
const QString &text);
|
||||
|
||||
class SignalBlocker {
|
||||
QWidget *widget;
|
||||
bool blocked;
|
||||
|
Loading…
Reference in New Issue
Block a user