Browse Source

Better error handling

QGC4.4
Don Gagne 10 years ago
parent
commit
ea722c4824
  1. 16
      src/QGCQmlWidgetHolder.cpp
  2. 2
      src/QGCQmlWidgetHolder.h

16
src/QGCQmlWidgetHolder.cpp

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
/// @author Don Gagne <don@thegagnes.com>
#include "QGCQmlWidgetHolder.h"
#include "QGCMessageBox.h"
QGCQmlWidgetHolder::QGCQmlWidgetHolder(QWidget *parent) :
QWidget(parent)
@ -43,8 +44,19 @@ void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot) @@ -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;
}

2
src/QGCQmlWidgetHolder.h

@ -50,7 +50,7 @@ public: @@ -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;

Loading…
Cancel
Save