#include <QStandardPaths>
源码分析:
public:
// Do not re-order, must match QDesktopServices
enum StandardLocation {
DesktopLocation,//桌面位置
DocumentsLocation,//文档位置
FontsLocation,//字体位置
ApplicationsLocation,//应用程序位置
MusicLocation,//音乐位置
MoviesLocation,//电影位置
PicturesLocation,//图片位置
TempLocation,
HomeLocation,
DataLocation,
CacheLocation,
GenericDataLocation,
RuntimeLocation,
ConfigLocation,
DownloadLocation,
GenericCacheLocation,
GenericConfigLocation,
AppDataLocation,
AppConfigLocation,
AppLocalDataLocation = DataLocation
};
Q_ENUM(StandardLocation)
static QString writableLocation(StandardLocation type);
static QStringList standardLocations(StandardLocation type);
static QString writableLocation(StandardLocation type);
这个函数返回给定StandardLocation类型的可写路径。这对于创建或修改文件非常有用。
static QStringList standardLocations(StandardLocation type);
这个函数返回一个QStringList,其中包含给定StandardLocation类型的所有相关路径。在某些情况下,一个标准位置可能解析为多个路径(尤其是在多用户或网络环境中)。
QString lastPath1 =QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
qDebug()<<lastPath1;//"C:/Users/XXXX/Pictures"