on xenial help sign in
Show a barebones error message if somehow loading the QML doesn't work
commitf2f43904b2e0e25fce1ce0916b96e4b746a4c73b authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 15 Feb 2017, 15:15 (10 years ago) parent66888de
1 file changed+21
src/ShellView.cpp+21
src/ShellView.cpp+21
@@ -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,24 @@ 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->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+
3556 QUrl source(::qmlDirectory() + "/OrientedShell.qml");
3657 setSource(source);
3758