Sunday, 13 October 2013

Files paths using Qt/C++ and Android

Today I've been mostly looking at the storage of my app data files within Android.

The two alternatives distribution systems for data files seem to be:

(i) using the Qt resource system (.qrc files)

(ii) adding the files to an android/asset directory and referencing these files from the code directly (see PDF in previous post for more details on how to set your .pro file to do this).

Method (i) seems to be best for files that will not change much between distributions and which the user is not much interested in (e.g. icons, shader files etc).

However, for example files (which the user may wish to edit), I think a better alternative is to keep them explicitly in the main file system so that the user can take a copy.

The difficulty with this method is that Android doesn't seem keen on you doing this.

I put my example files in the android/assets directory prior to packaging using Qt. Once installed the Qt functions can then acess them using the assets:/examples/ file path. However, standard C++ file types don't seem to work with this - perhaps because Qt has a link to the Android API that resolves the assets link back to an absolute link on the system.

The QDir::homePath() function seems to be able to help (see discussion here) - although I haven't been able to get it to work. I'll post back if I do.