QML数据文件夹 [英] QML data folder
问题描述
在我的应用程序基于 QML
我使用相机
和 CameraCapture
从相机捕获图像。捕获后,我想使用 CameraCapture.captureToLocation()
将捕获的图像存储在应用程序数据文件夹中。但我不知道如何获得这个文件夹的路径。所以我的问题 - 我怎么能得到应用程序文件夹的路径写的权限?有没有办法在Qt得到它?它应该是系统指定的文件夹,我猜。例如在Android中,它应该是/ data / data / AppName。
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.
推荐答案
/ data / data / AppName
未映射到 QStandardPaths < a>,但我认为最好使用这个:
/data/data/AppName
is not mapped in QStandardPaths, but I think it would be better to use this one:
QStandardPaths :: AppDataLocation 17返回一个目录位置,可以存储。这是一个特定于应用程序的目录。要获取存储要与其他应用程序共享的数据的路径,请使用QStandardPaths :: GenericDataLocation。返回的路径永远不为空。在Windows操作系统上,这将返回漫游路径。此枚举值已在Qt 5.4中添加。
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返回与AppLocalDataLocation相同的值。此枚举值已弃用。使用AppDataLocation是首选,因为在Windows上,建议使用漫游路径。
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
。
从5.4开始,后者被废除为文件。您可以将其设置为以下:
But note that from 5.4 on, the latter is deprecated as documented. You can set it then as follows:
QString QStandardPaths :: writableLocation(StandardLocation type)
QString QStandardPaths::writableLocation(StandardLocation type)
返回文件
注意:返回的存储位置可以是不存在的目录,也可以是不存在的目录。
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甚至不支持它:
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:
ApplicationsLocation不支持(目录不可读)
ApplicationsLocation not supported (directory not readable)
如果要跨应用程序共享图像,则需要使用此方法,并对上述代码进行细微调整。虽然我想你想要上面的一个,它是有点不清楚你想要哪一个,所以我提到两个:
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:
StandardPaths :: GenericDataLocation 11返回可以存储应用程序共享的持久数据的目录位置。这是一个通用值。返回的路径永远不为空。
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,因为没有固定链接到那个部分。你也可以检查自己,这是最好的。
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.
这篇关于QML数据文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!