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:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user