c-QML数据文件夹
作者:互联网
我的应用基于QML,我使用Camera和CameraCapture捕获相机中的图像.捕获后,我想使用CameraCapture.captureToLocation()将捕获的图像存储在应用程序数据文件夹中.但是我不知道如何获取该文件夹的路径.所以我的问题-如何获得具有写权限的应用程序文件夹的路径? Qt中有办法得到它吗?我猜应该是系统指定的文件夹.例如,在Android中,它应该是/ data / data / AppName.如我所见,LocalStorage在类似的位置创建其文件.
解决方法:
/ data / data / AppName未在QStandardPaths中映射,但我认为最好使用这一名称:
QStandardPaths::AppDataLocation 17 Returns a directory location where persistent application data can be stored. This is an application-specific directory. To obtain a path to store data to be shared with other applications, use QStandardPaths::GenericDataLocation. The returned path is never empty. On the Windows operating system, this returns the roaming path. This enum value was added in Qt 5.4.
或早期版本中的这个:
QStandardPaths::DataLocation 9 Returns the same value as AppLocalDataLocation. This enumeration value is deprecated. Using AppDataLocation is preferable since on Windows, the roaming path is recommended.
这些设置将在Android下设置为DataLocation“< APPROOT> / files”,“< USER> /< APPNAME> / files”.
但请注意,从5.4开始,已记录的文档已弃用后者.您可以将其设置为follows:
QString QStandardPaths::writableLocation(StandardLocation type)
Returns the directory where files of type should be written to, or an empty string if the location cannot be determined.
Note: The storage location returned can be a directory that does not exist; i.e., it may need to be created by the system or the user.
因此,您将编写如下内容:
QString dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
// Do not need to check against empty string for this value as per documentatio
CameraCapture.captureToLocation(dataPath);
注意:请勿为此目的使用QStandardPaths :: ApplicationsLocation,因为这是非专用位置.此外,Android甚至不支持它:
ApplicationsLocation not supported (directory not readable)
如果要在应用程序之间共享图像,则需要对上面的代码进行较小的调整来使用它.虽然我认为您想要上面的一个,但是还不清楚您想要哪个,所以我同时提到这两个:
StandardPaths::GenericDataLocation 11 Returns a directory location where persistent data shared across applications can be stored. This is a generic value. The returned path is never empty.
设置为GenericDataLocation“< USER>”在Android上.类文档中提到了确切的映射,您只需要向下滚动到表即可.我无法提供直接的网址,因为该部分没有固定链接.您也可以检查一下自己,这才是最合适的.
标签:qtcore,c,qt,qml,qtmultimedia 来源: https://codeday.me/bug/20191011/1896298.html