on xenial help sign in
Show a barebones error message if loading the QML doesn't work

Approved by: Michael Zanetti, Unity8 CI Bot

commit74d637c107c41f9d7fa338ef0f3ea4c2e9a3f78a authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 8 Mar 2017, 09:49 (10 years ago) parent1a5324d68b5263
1 file changed+22
src/ShellView.cpp+22
src/ShellView.cpp+22
@@ -19,6 +19,9 @@
1919// Qt
2020#include <QQmlContext>
2121#include <QQuickItem>
22+#include <QtQuick/private/qquickitem_p.h>
23+#include <QtQuick/private/qquickrectangle_p.h>
24+#include <QtQuick/private/qquicktext_p.h>
2225
2326// local
2427#include <paths.h>
@@ -32,6 +35,25 @@ ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
3235
3336 rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
3437
38+ connect(this, &QQuickView::statusChanged, this, [this] {
39+ if (status() == QQuickView::Error) {
40+ QQuickRectangle *rect = new QQuickRectangle(contentItem());
41+ rect->setColor(Qt::white);
42+ QQuickItemPrivate::get(rect)->anchors()->setFill(contentItem());
43+
44+ QString errorsString;
45+ for(const QQmlError &e: errors()) {
46+ errorsString += e.toString() + "\n";
47+ }
48+ QQuickText *text = new QQuickText(rect);
49+ text->setColor(Qt::black);
50+ text->setWrapMode(QQuickText::Wrap);
51+ text->setText(QString("There was an error loading Unity8:\n%1").arg(errorsString));
52+ QQuickItemPrivate::get(text)->anchors()->setFill(rect);
53+ }
54+ }
55+ );
56+
3557 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
3658 setSource(source);
3759