on xenial help sign in
Show a barebones error message if somehow loading the QML doesn't work
f2f4390Albert Astals Cid
src/ShellView.cpp+21
@@ -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,24 @@ 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->setWrapMode(QQuickText::Wrap);
50+ text->setText(QString("There was an error loading Unity8:\n%1").arg(errorsString));
51+ QQuickItemPrivate::get(text)->anchors()->setFill(rect);
52+ }
53+ }
54+ );
55+
35 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
56 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
36 setSource(source);
57 setSource(source);
37
58