From 58046eb249150169907ef4556fbbc5fd0aa9fa6c Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 19 Jun 2020 18:52:26 +0200 Subject: [PATCH] Main: [skip ci] replace QThread with std::thread as it won't start without an event loop --- src/Main/FreeCADGuiPy.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Main/FreeCADGuiPy.cpp b/src/Main/FreeCADGuiPy.cpp index f5250adebb..55646793f4 100644 --- a/src/Main/FreeCADGuiPy.cpp +++ b/src/Main/FreeCADGuiPy.cpp @@ -39,6 +39,7 @@ #elif defined(Q_WS_X11) #include #endif +#include // FreeCAD Base header #include #include @@ -55,23 +56,6 @@ static QWidget* setupMainWindow(); -class GUIThread : public QThread -{ -public: - GUIThread() - { - } - void run() - { - static int argc = 0; - static char **argv = {0}; - QApplication app(argc, argv); - if (setupMainWindow()) { - app.exec(); - } - } -}; - #if defined(Q_OS_WIN) HHOOK hhook; @@ -90,11 +74,22 @@ FreeCADGui_showMainWindow(PyObject * /*self*/, PyObject *args) if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &inThread)) return NULL; - static GUIThread* thr = 0; + static bool thr = false; if (!qApp) { - if (PyObject_IsTrue(inThread)) { - if (!thr) thr = new GUIThread(); - thr->start(); + if (PyObject_IsTrue(inThread) && !thr) { + thr = true; + std::thread t([]() { + static int argc = 0; + static char **argv = {0}; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) + QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); +#endif + QApplication app(argc, argv); + if (setupMainWindow()) { + app.exec(); + } + }); + t.detach(); } else { #if defined(Q_OS_WIN)