From ea722c48243484934abc0aeb95ab6d6f82bfebfc Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 18 Feb 2015 12:55:36 -0800 Subject: [PATCH] Better error handling --- src/QGCQmlWidgetHolder.cpp | 16 ++++++++++++++-- src/QGCQmlWidgetHolder.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/QGCQmlWidgetHolder.cpp b/src/QGCQmlWidgetHolder.cpp index 986633c5e..5da881ce4 100644 --- a/src/QGCQmlWidgetHolder.cpp +++ b/src/QGCQmlWidgetHolder.cpp @@ -25,6 +25,7 @@ /// @author Don Gagne #include "QGCQmlWidgetHolder.h" +#include "QGCMessageBox.h" QGCQmlWidgetHolder::QGCQmlWidgetHolder(QWidget *parent) : QWidget(parent) @@ -43,8 +44,19 @@ void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot) _ui.qmlWidget->rootContext()->setContextProperty("autopilot", autoPilot); } -void QGCQmlWidgetHolder::setSource(const QUrl& qmlUrl) +bool QGCQmlWidgetHolder::setSource(const QUrl& qmlUrl) { _ui.qmlWidget->setSource(qmlUrl); - _ui.qmlWidget->setMinimumSize(_ui.qmlWidget->rootObject()->width(), _ui.qmlWidget->rootObject()->height()); + if (_ui.qmlWidget->status() != QQuickWidget::Ready) { + QString errorList; + + foreach (QQmlError error, _ui.qmlWidget->errors()) { + errorList += error.toString(); + errorList += "\n"; + } + QGCMessageBox::warning(tr("Qml Error"), tr("Source not ready: %1\nErrors:\n%2").arg(_ui.qmlWidget->status()).arg(errorList)); + return false; + } + + return true; } diff --git a/src/QGCQmlWidgetHolder.h b/src/QGCQmlWidgetHolder.h index 90b8e084c..0cfb8a999 100644 --- a/src/QGCQmlWidgetHolder.h +++ b/src/QGCQmlWidgetHolder.h @@ -50,7 +50,7 @@ public: void setAutoPilot(AutoPilotPlugin* autoPilot); /// Sets the QML into the control - void setSource(const QUrl& qmlUrl); + bool setSource(const QUrl& qmlUrl); private: Ui::QGCQmlWidgetHolder _ui; -- 2.22.0