on xenial help sign in
Show a barebones error message if loading the QML doesn't work
74d637cAlbert Astals Cid
src/ShellView.cpp+22
@@ -19,6 +19,9 @@
19// Qt
19// Qt
20#include <QQmlContext>
20#include <QQmlContext>
21#include <QQuickItem>
21#include <QQuickItem>
22+#include <QtQuick/private/qquickitem_p.h>
23+#include <QtQuick/private/qquickrectangle_p.h>
24+#include <QtQuick/private/qquicktext_p.h>
22
25
23// local
26// local
24#include <paths.h>
27#include <paths.h>
@@ -32,6 +35,25 @@ ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
32
35
33 rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
36 rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
34
37
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+
35 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
57 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
36 setSource(source);
58 setSource(source);
37
59