Qt获取系统相关位置

在使用比如打开文件对话框(QFileDialog)时,想让其打开位置位于用户桌面等位置

Qt为我们提供了函数,使其实现起来十分方便

首先要引用头文件

[cpp]  view plain copy
  1. #include <QDesktopServices>  

然后可以通过如下语句获取不同的路径

[cpp]  view plain copy
  1. QString QStandardPaths::writableLocation(StandardLocation type)  

也可以通过一下语句获取路径下的文件和文件夹

[cpp]  view plain copy
  1. QStringList QStandardPaths::standardLocations(StandardLocation type)  

参数为路径名字的指代值,列表如下

QStandardPaths::DesktopLocation 0 Returns the user's desktop directory.
QStandardPaths::DocumentsLocation 1 Returns the user's document.
QStandardPaths::FontsLocation 2 Returns the user's fonts.
QStandardPaths::ApplicationsLocation 3 Returns the user's applications.
QStandardPaths::MusicLocation 4 Returns the user's music.
QStandardPaths::MoviesLocation 5 Returns the user's movies.
QStandardPaths::PicturesLocation 6 Returns the user's pictures.
QStandardPaths::TempLocation 7 Returns the system's temporary directory.
QStandardPaths::HomeLocation 8 Returns the user's home directory.
QStandardPaths::DataLocation 9 Returns a directory location where persistent application data can be 
stored. QCoreApplication::organizationName and
QCoreApplication::applicationName are appended to the directory location returned for GenericDataLocation.
QStandardPaths::CacheLocation 10 Returns a directory location where user-specific non-essential (cached) data should be written.
QStandardPaths::GenericCacheLocation 15 Returns a directory location where user-specific non-essential (cached) data, shared across applications, should be written.
QStandardPaths::GenericDataLocation 11 Returns a directory location where persistent data shared across applications can be stored.
QStandardPaths::RuntimeLocation 12 Returns a directory location where runtime communication files should be written. For instance unix local sockets.
QStandardPaths::ConfigLocation 13 Returns a directory location where user-specific configuration files should be written.
QStandardPaths::DownloadLocation 14 Returns a directory for user's downloaded files.

转自:http://blog.csdn.net/vinson0526/article/details/9126495

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值