summaryrefslogtreecommitdiffstats
path: root/tradeshow/iot-sensortag/main.cpp
diff options
context:
space:
mode:
authorKari Hautamäki <kari.hautamaki@qt.io>2017-02-09 13:39:06 +0200
committerTitta Heikkala <titta.heikkala@qt.io>2017-02-09 13:00:12 +0000
commita3447ec9896902354d89284cafba1e1dbac17774 (patch)
treec266819f86cb41f3f79386b53585ccb3af54c751 /tradeshow/iot-sensortag/main.cpp
parent4126977c5a683475335df289c088c11439afa548 (diff)
iot-sensortag: Add option to enable deploying resources to the file system
Add a config flag to the project file that controls how resources are deployed with the binary. By default they are included in the binary but it is also possible to deploy them to the file system. This option is needed as Qt5.7.1 and and Qt5.8 fail to load QML files from resource files on some platforms (e.g. RPi3). Change-Id: I7e1e938ac829d01ac6117e04bbaef053daf15154 Reviewed-by: Titta Heikkala <titta.heikkala@qt.io>
Diffstat (limited to 'tradeshow/iot-sensortag/main.cpp')
-rw-r--r--tradeshow/iot-sensortag/main.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/tradeshow/iot-sensortag/main.cpp b/tradeshow/iot-sensortag/main.cpp
index 2fcc749..be8ea60 100644
--- a/tradeshow/iot-sensortag/main.cpp
+++ b/tradeshow/iot-sensortag/main.cpp
@@ -120,7 +120,6 @@ int main(int argc, char *argv[])
else {
qCDebug(boot2QtDemos) << "Unknown mode: " << sensorSource;
return 1;
-
}
qmlRegisterType<SensorTagDataProvider>("SensorTag.DataProvider", 1, 0, "SensorTagData");
@@ -135,6 +134,14 @@ int main(int argc, char *argv[])
}
#endif
+#ifdef DEPLOY_TO_FS
+ QString namingScheme = QStringLiteral("file://") + qApp->applicationDirPath();
+ qCDebug(boot2QtDemos) << "Loading resources from the directory" << namingScheme;
+#else
+ QString namingScheme = QStringLiteral("qrc://");
+ qCDebug(boot2QtDemos) << "Loading resources from a resource file";
+#endif
+
QString mainFile;
QUrl styleFile;
QString uiVariant;
@@ -149,8 +156,9 @@ int main(int argc, char *argv[])
qCDebug(boot2QtDemos) << "Scale factor:" << sf.data();
#if defined(UI_SMALL)
- mainFile = QStringLiteral("qrc:/resources/small/MainSmall.qml");
- styleFile = QUrl("qrc:/resources/small/StyleSmall.qml");
+ mainFile = namingScheme + QStringLiteral("/resources/small/MainSmall.qml");
+ styleFile = namingScheme + QStringLiteral("/resources/small/StyleSmall.qml");
+
uiVariant = "small";
fullScreen = true;
appWidth = 1920;
@@ -184,8 +192,12 @@ int main(int argc, char *argv[])
}
QQmlApplicationEngine engine;
- engine.rootContext()->setContextProperty("pathPrefix", "/resources/" + uiVariant + "/images/");
- engine.load(QUrl(QStringLiteral("qrc:/resources/base/main.qml")));
+ engine.rootContext()->setContextProperty("pathPrefix", namingScheme + +"/resources/" + uiVariant + "/images/");
+#ifdef DEPLOY_TO_FS
+ engine.load(QUrl::fromLocalFile(qApp->applicationDirPath() + QStringLiteral("/resources/base/main.qml")));
+#else
+ engine.load(QUrl(QStringLiteral("qrc:///resources/base/main.qml")));
+#endif
QQuickWindow *item = qobject_cast<QQuickWindow *>(engine.rootObjects()[0]);
if (item) {