Qt程序关于路径、用户目录路径、临时文件夹位置获取方法

1、获取程序所在目录:QString QCoreApplication::applicationDirPath()

2、获取程序完成目录及名称:QString QCoreApplication::applicationFilePath()

3、获取当前工作目录:QString QDir::currentPath()

4、获取家目录:QString QDir::homePath()

5、获取根目录:QString QDir::rootPath()

6、获取临时文件目录:QString QDir::tempPath()

7、用户目录路径

  Qt 5 中引入的方法

  QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
  QStandardPaths::standardLocations(QStandardPaths::HomeLocation);

  这两个方法的区别是 standardLocations() 返回值是 QStringList。当然对于 HomeLocation 来说这个 QStringList 中只有一个 QString。

  还有另外一种方法,利用 QDir 类的一个静态函数:

  QDir::homePath();

8、我的文档路径

   Qt 5 中引入的方法。

  QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);

  QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);

9、桌面路径

  QStandardPaths::writableLocation(QStandardPaths::Deskto

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值