diff options
author | Kari Hautamäki <kari.hautamaki@qt.io> | 2017-02-09 13:39:06 +0200 |
---|---|---|
committer | Titta Heikkala <titta.heikkala@qt.io> | 2017-02-09 13:00:12 +0000 |
commit | a3447ec9896902354d89284cafba1e1dbac17774 (patch) | |
tree | c266819f86cb41f3f79386b53585ccb3af54c751 /tradeshow | |
parent | 4126977c5a683475335df289c088c11439afa548 (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')
-rw-r--r-- | tradeshow/iot-sensortag/SensorTagDemo.pro | 27 | ||||
-rw-r--r-- | tradeshow/iot-sensortag/main.cpp | 22 |
2 files changed, 40 insertions, 9 deletions
diff --git a/tradeshow/iot-sensortag/SensorTagDemo.pro b/tradeshow/iot-sensortag/SensorTagDemo.pro index 752ea9b..e92ce14 100644 --- a/tradeshow/iot-sensortag/SensorTagDemo.pro +++ b/tradeshow/iot-sensortag/SensorTagDemo.pro @@ -4,6 +4,10 @@ QT += 3dcore 3drender 3dinput 3dquick 3dlogic core gui qml quick 3dquickextras w QT += bluetooth network CONFIG += c++11 +# To overcome the bug QTBUG-58648, uncomment this define +# Needed at least for RPi3 and iMX +#CONFIG += DEPLOY_TO_FS + # Uncomment DEVICE_TYPE and assign either UI_SMALL, UI_MEDIUM, UI_LARGE # to force using that UI form factor. Otherwise # the form factor is determined based on the platform @@ -90,19 +94,25 @@ RESOURCES += base.qrc equals(DEVICE_TYPE, "UI_SMALL") { DEFINES += UI_SMALL - RESOURCES += uismall.qrc + !DEPLOY_TO_FS: RESOURCES += uismall.qrc + uiVariant.files = resources/small + uiVariant.path = /opt/$${TARGET}/resources message("Resource file for SMALL display picked") } equals(DEVICE_TYPE, "UI_MEDIUM") { DEFINES += UI_MEDIUM - RESOURCES += uimedium.qrc + !DEPLOY_TO_FS: RESOURCES += uimedium.qrc + uiVariant.files = resources/medium + uiVariant.path = /opt/$${TARGET}/resources message("Resource file for MEDIUM display picked") } equals(DEVICE_TYPE, "UI_LARGE") { DEFINES += UI_LARGE - RESOURCES += uilarge.qrc + !DEPLOY_TO_FS: RESOURCES += uilarge.qrc + uiVariant.files = resources/large + uiVariant.path = /opt/$${TARGET}/resources message("Resource file for LARGE display picked") } @@ -111,8 +121,17 @@ QML_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET} !isEmpty(target.path): INSTALLS += target DISTFILES += \ android-sources/AndroidManifest.xml + +DEPLOY_TO_FS { + message("Files will be deployed to the file system") + DEFINES += DEPLOY_TO_FS + + baseFiles.files = resources/base + baseFiles.path = /opt/$${TARGET}/resources + INSTALLS += baseFiles uiVariant +} 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) { |