Qt获取系统相关位置
2016-07-15 14:20
483 查看
在使用比如打开文件对话框(QFileDialog)时,想让其打开位置位于用户桌面等位置
Qt为我们提供了函数,使其实现起来十分方便
Qt4--Qt5用QDesktopServices;
首先要引入头文件
=====================================================================================================================
Qt5以后用QStandardPaths;
首先要引用头文件
然后可以通过如下语句获取不同的路径
例如:获取桌面路径
参数为路径名字的指代值,列表如下
Qt为我们提供了函数,使其实现起来十分方便
Qt4--Qt5用QDesktopServices;
首先要引入头文件
#include <QDesktopServices>然后可以通过如下语句获取不同的路径
static QString QDesktopServices::storageLocation(StandardLocation type);例如:获取桌面路径
//获取桌面路径 QString path = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
=====================================================================================================================
Qt5以后用QStandardPaths;
首先要引用头文件
#include <QStandardPaths>
然后可以通过如下语句获取不同的路径
static QString writableLocation(StandardLocation type);也可以通过一下语句获取路径下的文件和文件夹(注意:该函数返回值类型是list)
static QStringList standardLocations(StandardLocation type);
例如:获取桌面路径
QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
参数为路径名字的指代值,列表如下
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. |
相关文章推荐
- Qt creator 使用 qwt 控件
- Qt申请窗口类对象,构造函数无法解析
- NCReport配置并测试
- QDateTime类遇到的问题
- QT 下 SQlite3 数据库加密及 CppSQLite3 操作数据库加密
- Qt pro 文件详解
- QT学习之-HelloWorld
- 【Qt】2.2 继续了解信号和槽
- QString类遇到的一些问题
- Qt Mac OS、iOS和X11的Retina显示支持
- Qt 去掉窗体标题栏、窗体透明、窗体圆角(一)
- Qt 之 show,hide,setVisible,setHidden,close 等小结
- 基于Mqtt的即时通信
- mqtt之初步探索
- Qt5 - 中文 - 常量中有换行符
- Qt快速入门系列教程目录
- QT pro文件编写
- Qt 关于在Debug环境下打包程序
- Qt5.7配合mysql免安装版使用,Drive not loaded的错误解决
- 关于QT字库的移植和使用总结(能够任意改变字体和颜色)