[Development] QML Runtime / data file deployment

Sorvig Morten Morten.Sorvig at digia.com
Wed Jan 16 10:59:49 CET 2013


On Dec 24, 2012, at 8:22 AM, Alan Alpert <416365416c at gmail.com> wrote:

> For those interested in the matter, the discussion has now moved to codereview.
> 
> https://codereview.qt-project.org/#change,43539 adds the QQmlApplicationEngine
> https://codereview.qt-project.org/#change,43540 adds the qml tool using it
> 
> The one thing missing from QQmlApplicationEngine is the resolution of
> different paths for different platforms. I'd be interested in ideas on
> how best to expose that, it might even be part of a more general
> device-independent code discussion. But I think that can wait for the
> next patch to QQmlApplicationEngine, it's still useful for the cases
> where you know your platform/path already.


I startet mapping out a solution to this a while ago but was unable to find something workable:  I ended up using a preprocessor macro which does not work from QML. I'll post it here anyway, perhaps someone else can pick it up and find a better solution.

The core of the problem (with this solution) seems to be setting a data path at build time, reading and overriding it at deploy time, and then finally reading it at runtime from C++ and QML.

A different approach exist in the form of qFindTestData(qtestcase.cpp), which searches various locations for data files. 

Here's my proposal:

1) The app author places the data files in a designated directory and adds an entry to the .pro file:

APPDATAPATH = $$PWD/data

2) At runtime the path and files can be found again using a QAPPDATAPATH macro

QString filePath = QAPPDATAPATH + "/myfile";
QFile file(filePath);
file.open(QIODevice::ReadOnly) // We only guarantee read access.

(If we can get away from a macro to something nicer like "QDesktopServices::AppDataLocation" we should definitively do that. The challenge is how to set it at app compile time.)

3) Moving the files and setting AppDataLocation is done at the build and/or deployment stage. This will vary depending on the Qt configuration and platform.

Some cases (where I know the details):
- developer builds: No copying required. AppDataLocation points directly to APPDATAPATH in the source dir.
- prefix builds: The contents of APPDATAPATH is copied during "make install" and AppDataLocation is set to the install location.
- iOS/Xocde integration: Add files to "Resources" folder in project. Set AppDataLocation to point to "Resources" in the app bundle.
- macdeployqt: Copy files to the app bundle. Set AppDataLocation like the Xcode case.

AppDataLocation needs to be set at build/deploy time, for example using qt.conf similar to how we set the plugin path today.

Morten




More information about the Development mailing list