Qt各类Windows系统路径获取

本文详细介绍了Qt库中在Windows系统下定义的一系列标准路径常量,如桌面、文档、字体等,以及不同Qt版本对应的特定应用程序路径和缓存数据位置。
摘要由CSDN通过智能技术生成
#include <QStandardPaths>
#include <QCoreApplication>

//以下所有注释均针对Windows系统而言
//对于中文语言的Windows系统, C:/用户/... 和  C:/User/... 是相同的
//对于以下的注释内容,C:/用户/.../   /用户/  后面的三个点均指代电脑的用户名称
#define desktopPath QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)  // 桌面路径
#define documentPath QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) // 文档路径
#define fontPath QStandardPaths::writableLocation(QStandardPaths::FontsLocation) // 字体文件路径
#define applicationsPath QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) // 开始菜单程序路径
#define musicPath QStandardPaths::writableLocation(QStandardPaths::MusicLocation) // 音乐路径
#define moviesPath QStandardPaths::writableLocation(QStandardPaths::MoviesLocation) // 视频路径
#define picturesPath QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) // 图片路径
#define tempPath QStandardPaths::writableLocation(QStandardPaths::TempLocation) // 临时文件路径
#define homePath QStandardPaths::writableLocation(QStandardPaths::HomeLocation) // 主目录路径
#define cachePath QStandardPaths::writableLocation(QStandardPaths::CacheLocation) // 本应用程序的缓存路径(参考上一行注释: C:/用户/.../AppAppData/Local/ + 本项目名称 + /cache ,该路径可能是不存在的)
#define genericCachePath QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) // 系统通用缓存目录路径(参考: C:/用户/.../AppData/Local/cache)
#define genericDataPath QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) // 系统通用数据目录路径 (参考: C:/用户/.../AppData/Local)
// #define runTimePath QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation)//意义不明,区别于最后一个 runPath 参考:C:/Users/... 为了不与最后一项产生歧义和误解,这里将之注释掉
#define configPath QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) // 似乎与appLocalDataPath是相同的
#define downloadPath QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) // 下载路径
#define genericConfigPath QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) // 通用配置目录路径 似乎与genericDataPath是相同的

#if (QT_VERSION >= QT_VERSION_CHECK(5,4,0)) // Qt5.4及以上生效
#define appLocalDataPath QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) // 本程序的配置文件、数据文件等默认的系统目录路径(返回值是默认的系统应用数据路径加上本项目名称,即大部分软件的默认安装路径 C:/用户/.../AppData/Local/ + 本项目名称,该路径可能是不存在的)
#define appDataPath QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) // 本应用程序数据路径 (参考:C:/用户/.../AppData/Roaming/ + 本项目名称 ,大部分情况下也是存储一些配置文件或者缓存文件)
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,5,0)) // Qt5.5及以上生效
#define appConfigPath QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) // 本应用程序配置目录路径,似乎与appLocalDataPath是相同的 参考:C:/用户/.../AppData/Local/ + 本项目名称
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(6,4,0)) // Qt6.4及以上生效
#define publicSharePath QStandardPaths::writableLocation(QStandardPaths::PublicShareLocation) //系统公共目录 参考:C:/Users/Public 或C:/用户/公用
#define templatesPath QStandardPaths::writableLocation(QStandardPaths::TemplatesLocation)//返回可存储特定于用户的模板文件的目录位置。这是一个泛型值。如果系统没有模板位置的概念,返回的路径可能为空。参考:C:/用户/.../AppData/Roaming/Microsoft/Windows/Templates
#endif


#define runPath QCoreApplication::applicationDirPath()  //本程序运行时的路径,即调用的exe运行时的路径,该路径是动态的

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值