diff --git a/src/qtquick/Platform_qtquick.cpp b/src/qtquick/Platform_qtquick.cpp index a3aafffe..36a94189 100644 --- a/src/qtquick/Platform_qtquick.cpp +++ b/src/qtquick/Platform_qtquick.cpp @@ -16,6 +16,7 @@ #include "views/View_qtquick.h" #include #include +#include static KDDockWidgets::Platform_qtquick s_platformQtQuick; @@ -28,9 +29,9 @@ Platform_qtquick::Platform_qtquick() // KDDockWidgets::registerQmlTypes(); // TODOv2 QQuickWindow::setDefaultAlphaBuffer(true); - qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) { - ViewWrapper *wrapper = new Views::ViewWrapper_qtquick(obj); - focusedViewChanged.emit(std::shared_ptr(wrapper)); + // Delay call to init(), so we have a QApplication + QTimer::singleShot(0, [this] { + init(); }); } @@ -38,6 +39,14 @@ Platform_qtquick::~Platform_qtquick() { } +void Platform_qtquick::init() +{ + qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) { + ViewWrapper *wrapper = obj ? new Views::ViewWrapper_qtquick(obj) : nullptr; + focusedViewChanged.emit(std::shared_ptr(wrapper)); + }); +} + const char *Platform_qtquick::name() const { return "qtquick"; diff --git a/src/qtquick/Platform_qtquick.h b/src/qtquick/Platform_qtquick.h index 5365698d..15d08bd9 100644 --- a/src/qtquick/Platform_qtquick.h +++ b/src/qtquick/Platform_qtquick.h @@ -24,6 +24,9 @@ public: ~Platform_qtquick() override; const char *name() const override; std::shared_ptr focusedView() const override; + +private: + void init(); }; } diff --git a/src/qtwidgets/Platform_qtwidgets.cpp b/src/qtwidgets/Platform_qtwidgets.cpp index 0f23c44f..cbcba88c 100644 --- a/src/qtwidgets/Platform_qtwidgets.cpp +++ b/src/qtwidgets/Platform_qtwidgets.cpp @@ -16,6 +16,7 @@ #include "qtwidgets/views/ViewWrapper_qtwidgets.h" #include +#include #include @@ -32,9 +33,9 @@ Platform_qtwidgets::Platform_qtwidgets() } #endif - qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) { - ViewWrapper *wrapper = new Views::ViewWrapper_qtwidgets(obj); - focusedViewChanged.emit(std::shared_ptr(wrapper)); + // Delay call to init(), so we have a QApplication + QTimer::singleShot(0, [this] { + init(); }); } @@ -42,6 +43,14 @@ Platform_qtwidgets::~Platform_qtwidgets() { } +void Platform_qtwidgets::init() +{ + qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) { + ViewWrapper *wrapper = obj ? new Views::ViewWrapper_qtwidgets(obj) : nullptr; + focusedViewChanged.emit(std::shared_ptr(wrapper)); + }); +} + const char *Platform_qtwidgets::name() const { return "qtwidgets"; diff --git a/src/qtwidgets/Platform_qtwidgets.h b/src/qtwidgets/Platform_qtwidgets.h index 33b0ff3e..d2dfcd7b 100644 --- a/src/qtwidgets/Platform_qtwidgets.h +++ b/src/qtwidgets/Platform_qtwidgets.h @@ -26,6 +26,9 @@ public: const char *name() const override; bool hasActivePopup() const override; std::shared_ptr focusedView() const override; + +private: + void init(); }; }