From 1c78c65b19c2f2061477625489a626137eaba094 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 20 Mar 2018 16:32:31 +0000 Subject: [PATCH] Popup an error box when QtQuick errors occur. --- src/GUI/LauncherMainWindow.cxx | 30 ++++++++++++++++++++++++++++++ src/GUI/LauncherMainWindow.hxx | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx index c18baca93..80d22662b 100644 --- a/src/GUI/LauncherMainWindow.cxx +++ b/src/GUI/LauncherMainWindow.cxx @@ -17,6 +17,7 @@ #include #include #include +#include // simgear headers #include @@ -171,6 +172,9 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->aircraftList->engine()->rootContext()->setContextProperty("_launcher", this); m_ui->aircraftList->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership); + + connect( m_ui->aircraftList, &QQuickWidget::statusChanged, + this, &LauncherMainWindow::onQuickStatusChanged); m_ui->aircraftList->setSource(QUrl("qrc:///qml/AircraftList.qml")); // settings @@ -181,6 +185,8 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->settings->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership); m_ui->settings->setResizeMode(QQuickWidget::SizeRootObjectToView); + connect( m_ui->settings, &QQuickWidget::statusChanged, + this, &LauncherMainWindow::onQuickStatusChanged); m_ui->settings->setSource(QUrl("qrc:///qml/Settings.qml")); // environemnt @@ -193,6 +199,9 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->environmentPage->engine()->rootContext()->setContextProperty("_config", m_config); m_ui->environmentPage->setResizeMode(QQuickWidget::SizeRootObjectToView); + + connect( m_ui->environmentPage, &QQuickWidget::statusChanged, + this, &LauncherMainWindow::onQuickStatusChanged); m_ui->environmentPage->setSource(QUrl("qrc:///qml/Environment.qml")); // summary @@ -200,6 +209,9 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->summary->engine()->rootContext()->setContextProperty("_launcher", this); m_ui->summary->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership); m_ui->summary->setResizeMode(QQuickWidget::SizeRootObjectToView); + + connect( m_ui->summary, &QQuickWidget::statusChanged, + this, &LauncherMainWindow::onQuickStatusChanged); m_ui->summary->setSource(QUrl("qrc:///qml/Summary.qml")); ////////////////////////// @@ -253,6 +265,24 @@ void LauncherMainWindow::initQML() PreviewImageItem::setGlobalNetworkAccess(netAccess); } +void LauncherMainWindow::onQuickStatusChanged(QQuickWidget::Status status) +{ + if (status == QQuickWidget::Error) { + QQuickWidget* qw = qobject_cast(sender()); + QString errorString; + + Q_FOREACH(auto err, qw->errors()) { + errorString.append("\n" + err.toString()); + } + + QMessageBox::critical(this, "UI loading failures.", + tr("Problems occurred loading the user interface. This is often due to missing modules on your system. " + "Please report this error to the FlightGear developer list or forum, and take care to mention your system " + "distribution, etc. Please also include the information provided below.\n") + + errorString); + } +} + LauncherMainWindow::~LauncherMainWindow() { // avoid a double-free when the QQuickWidget's engine seems to try diff --git a/src/GUI/LauncherMainWindow.hxx b/src/GUI/LauncherMainWindow.hxx index 1ecb13f3d..ff7bf6728 100644 --- a/src/GUI/LauncherMainWindow.hxx +++ b/src/GUI/LauncherMainWindow.hxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -200,6 +201,7 @@ private slots: void setSceneryPaths(); void onAircraftPathsChanged(); void onChangeDataDir(); + void onQuickStatusChanged(QQuickWidget::Status status); private: /**