StandardPaths QML Type

提供对标准系统路径的访问。更多

Import Statement: import Qt.labs.platform
Inherits:

QtObject

Status: Deprecated since 6.4

自 Qt.labs.platform 6.4 起,该类型已被弃用。我们强烈建议不要在新代码中使用它。

方法

详细说明

使用 QtCore::StandardPaths 代替。

StandardPaths 单例类型提供了查询标准系统路径的方法。标准路径主要与FileDialogFolderDialog 类型结合使用。

FileDialog {
    folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
}

注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。

另请参阅 QtCore::StandardPaths,FileDialog,FolderDialog, 和QStandardPaths

方法文档

string displayName(StandardLocation type)

返回给定位置的本地化显示名称type ,如果找不到相关位置,则返回空的QString

另请参阅 QStandardPaths::displayName() 。


url findExecutable(string executableName, list<string> paths)

在指定的paths 中查找名为executableName 的可执行文件,如果paths 为空,则查找系统路径。

在大多数操作系统中,系统路径由PATH 环境变量决定。搜索可执行文件的目录可在 paths 参数中设置。要同时在自己的路径和系统路径中搜索,可调用两次 findExecutable,一次在路径已设置的情况下,另一次在路径为空的情况下。如果可执行文件的行为取决于其调用的名称,则不会解析系统链接,以保护其行为。

注意: 在 Windows 系统中,通常的可执行文件扩展名(来自 PATHEXT 环境变量)会被自动添加。例如,findExecutable("foo") 调用会查找foo.exefoo.bat (如果存在)。

返回可执行文件的绝对路径,如果未找到,则返回空字符串。

如果给定的executableName 是指向可执行文件的绝对路径,则返回其干净路径。

另请参阅 QStandardPaths::findExecutable().


url locate(StandardLocation type, string fileName, LocateOptions options)

type 的标准位置查找名为fileName 的文件或目录。

通过options 标志,可以指定查找文件还是目录。默认情况下,该标志设置为LocateFile

返回找到的第一个文件或目录的绝对路径,否则返回空字符串。

另请参阅 QStandardPaths::locate() 。


list<url> locateAll(StandardLocation type, string fileName, LocateOptions options)

type 的标准位置查找名称为fileName 的所有文件或目录。

通过options 标志,可以指定是否查找文件或目录。默认情况下,该标记设置为LocateFile

返回找到的所有文件的列表。

另请参阅 QStandardPaths::locateAll() 。


void setTestModeEnabled(bool testMode)

如果testModetrue ,则会启用QStandardPaths 中的特殊 "测试模式",该模式会更改可写位置,使其指向测试目录。这将防止自动测试读取或写入当前用户的配置。

它会影响测试程序可能写入文件的位置:GenericDataLocation,AppDataLocation,ConfigLocation,GenericConfigLocation,AppConfigLocation,StateLocation,GenericStateLocation,GenericCacheLocation, 和CacheLocation 。其他位置不受影响。

在 Unix 上,XDG_DATA_HOME 设置为~/.qttest/shareXDG_CONFIG_HOME 设置为~/.qttest/configXDG_STATE_HOME 设置为~/.qttest/stateXDG_CACHE_HOME 设置为~/.qttest/cache

在 macOS 上,数据到~/.qttest/Application Support ,缓存到~/.qttest/Cache ,配置到~/.qttest/Preferences

在 Windows 系统中,所有内容都进入%APPDATA% 下的 "qttest "目录。

另请参阅 QStandardPaths::setTestModeEnabled() 。


list<url> standardLocations(StandardLocation type)

返回type 文件所在的所有目录。

目录列表按优先级从高到低排序,如果可以确定,则从writableLocation() 开始。如果没有定义类型的位置,则该列表为空。

另请参见 QStandardPaths::standardLocations()。


url writableLocation(StandardLocation type)

返回type 文件应写入的目录,如果无法确定位置,则返回空字符串。

注意: 返回的存储位置可能不存在;也就是说,它可能需要由系统或用户创建。

另请参阅 QStandardPaths::writableLocation().


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.