From e7f2cc384dfe71ea310f2a22c6cee2687f53c750 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 4 May 2018 15:30:40 -0700 Subject: [PATCH] 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. --- UI/qt-wrappers.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp index 7899387bf..5273f9298 100644 --- a/UI/qt-wrappers.hpp +++ b/UI/qt-wrappers.hpp @@ -17,8 +17,10 @@ #pragma once +#include #include #include +#include #include #include @@ -79,3 +81,10 @@ public: }; void DeleteLayout(QLayout *layout); + +static inline Qt::ConnectionType WaitConnection() +{ + return QThread::currentThread() == qApp->thread() + ? Qt::DirectConnection + : Qt::BlockingQueuedConnection; +}