gpt4 book ai didi

c++ - QML 数据文件夹

转载 作者:搜寻专家 更新时间:2023-10-31 01:02:23 32 4
gpt4 key购买 nike

我的应用程序基于 QML 我使用 CameraCameraCapture 从相机捕捉图像。捕获后,我想使用 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.

这些将被设置为 DataLocation "<APPROOT>/files", "<USER>/<APPNAME>/files"在 Android 上位于下方。

但请注意,从 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>"在安卓系统上。类文档中提到了确切的映射,您只需要向下滚动到表格即可。我无法提供直接 URL,因为该部分没有固定链接。您也可以自己检查一下,哪个最合适。

关于c++ - QML 数据文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27340317/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com