在使用比如打开文件对话框(QFileDialog)时,想让其打开位置位于用户桌面等位置
Qt为我们提供了函数,使其实现起来十分方便
首先要引用头文件
- #include <QDesktopServices>
然后可以通过如下语句获取不同的路径
- QString QStandardPaths::writableLocation(StandardLocation type)
也可以通过一下语句获取路径下的文件和文件夹
- 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. |