Don't access qApp directly from Platform's ctor

QApplication might not be created yet, so delay it
With a timer for now. Don't guarantee this will stay.
Explicit init by the user might be an alternative.
This commit is contained in:
Sergio Martins
2022-04-05 22:29:01 +01:00
parent 3ba4bc2d08
commit 793e48150a
4 changed files with 30 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
#include "qtwidgets/views/ViewWrapper_qtwidgets.h"
#include <QApplication>
#include <QTimer>
#include <memory.h>
@@ -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<ViewWrapper>(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<ViewWrapper>(wrapper));
});
}
const char *Platform_qtwidgets::name() const
{
return "qtwidgets";