Im my app based on QML
I use Camera
and CameraCapture
to capture an image from the camera. After it was captured I want to store captured image in application data folder with CameraCapture.captureToLocation()
. But I have no idea how to get path to this folder. So my question - how can I get path to application folder wit write permissions? Is there way in Qt to get it? It should be system specified folder, I guess. For example in Android it should be /data/data/AppName. As I see LocalStorage creates its files in some similar place.
QML data folder
3.1k Views Asked by folibis At
2
There are 2 best solutions below
1

You can use QStandardPaths
to specify a writable location :
QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) ;
Here QStandardPaths::GenericDataLocation
returns a directory location where persistent data shared across applications can be stored and it is never empty.
It's also possible use QStandardPaths::ApplicationsLocation
or many others which could be found here. You can implement a function in C++ side and use it in your QML to get the standard location.
/data/data/AppName
is not mapped in QStandardPaths, but I think it would be better to use this one:or this one in earlier versions:
These will be set to
DataLocation "<APPROOT>/files", "<USER>/<APPNAME>/files"
underneath on Android.But note that from 5.4 on, the latter is deprecated as documented. You can set it then as follows:
So, you would write something like this:
Note: Please do not use
QStandardPaths::ApplicationsLocation
for this purpose since that is the non-dedicated location. In addition, it is even unsupported on Android:If you want to share the image across applications, you would need to use this with minor adjustment to the code above. While I think you wanted the one above, it is a bit unclear which one you wanted, so I am mentioning both:
This is set to
GenericDataLocation "<USER>"
on Android. The exact mappings are mentioned in the class documentation, you just need to scroll down to the tables. I cannot give direct URL as there is no permalink to that section. You can check yourself, too, which fits the best.