1、获取程序所在目录:QString QCoreApplication::applicationDirPath()
2、获取程序完成目录及名称:QString QCoreApplication::applicationFilePath()
3、获取当前工作目录:QString QDir::currentPath()
4、获取家目录:QString QDir::homePath()
5、获取根目录:QString QDir::rootPath()
6、获取临时文件目录:QString QDir::tempPath()
7、用户目录路径
Qt 5 中引入的方法
QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
这两个方法的区别是 standardLocations() 返回值是 QStringList。当然对于 HomeLocation 来说这个 QStringList 中只有一个 QString。
还有另外一种方法,利用 QDir 类的一个静态函数:
QDir::homePath();
8、我的文档路径
Qt 5 中引入的方法。
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
9、桌面路径
QStandardPaths::writableLocation(QStandardPaths::Deskto