您的位置:首页 > 编程语言 > Qt开发

Qt获取系统相关位置

2013-06-19 10:36 344 查看
在使用比如打开文件对话框(QFileDialog)时,想让其打开位置位于用户桌面等位置

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

首先要引用头文件

#include <QDesktopServices>


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

QString QStandardPaths::writableLocation(StandardLocation type)


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

QStringList QStandardPaths::standardLocations(StandardLocation type)


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

QStandardPaths::DesktopLocation0Returns the user's desktop directory.
QStandardPaths::DocumentsLocation1Returns the user's document.
QStandardPaths::FontsLocation2Returns the user's fonts.
QStandardPaths::ApplicationsLocation3Returns the user's applications.
QStandardPaths::MusicLocation4Returns the user's music.
QStandardPaths::MoviesLocation5Returns the user's movies.
QStandardPaths::PicturesLocation6Returns the user's pictures.
QStandardPaths::TempLocation7Returns the system's temporary directory.
QStandardPaths::HomeLocation8Returns the user's home directory.
QStandardPaths::DataLocation9Returns 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::CacheLocation10Returns a directory location where user-specific non-essential (cached) data should be written.
QStandardPaths::GenericCacheLocation15Returns a directory location where user-specific non-essential (cached) data, shared across applications, should be written.
QStandardPaths::GenericDataLocation11Returns a directory location where persistent data shared across applications can be stored.
QStandardPaths::RuntimeLocation12Returns a directory location where runtime communication files should be written. For instance unix local sockets.
QStandardPaths::ConfigLocation13Returns a directory location where user-specific configuration files should be written.
QStandardPaths::DownloadLocation14Returns a directory for user's downloaded files.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Qt