From 74cda9a2ccce22efd57237e263ae2091be6db2ad Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 6 Feb 2019 12:04:31 -0800 Subject: [PATCH] UI: Add CreateQThread helper function Allows creating a QThread via an std::function. A backward-compatible alternative to QThread::create for Qt versions older than 5.10 (when it became available in Qt). --- UI/qt-wrappers.cpp | 20 ++++++++++++++++++++ UI/qt-wrappers.hpp | 3 +++ 2 files changed, 23 insertions(+) diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp index eac5ea0f3..b37d2b9a5 100644 --- a/UI/qt-wrappers.cpp +++ b/UI/qt-wrappers.cpp @@ -203,3 +203,23 @@ void DeleteLayout(QLayout *layout) delete layout; } + +class QuickThread : public QThread { +public: + explicit inline QuickThread(std::function func_) + : func(func_) + {} + +private: + virtual void run() override + { + func(); + } + + std::function func; +}; + +QThread *CreateQThread(std::function func) +{ + return new QuickThread(func); +} diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp index 5273f9298..d56fa52ae 100644 --- a/UI/qt-wrappers.hpp +++ b/UI/qt-wrappers.hpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -64,6 +65,8 @@ QDataStream &operator>>(QDataStream &in, OBSScene &scene); QDataStream &operator<<(QDataStream &out, const OBSSceneItem &si); QDataStream &operator>>(QDataStream &in, OBSSceneItem &si); +QThread *CreateQThread(std::function func); + class SignalBlocker { QWidget *widget; bool blocked; -- GitLab