1、示例代码
void MyWidget::demo()
{
// 1.获取当前运行程序的目录路径
QString applicationDirPath = QCoreApplication::applicationDirPath();
// 2.获取当前工作目录
QString currentPath = QDir::currentPath();
qDebug()<<"applicationDirPath:"<<applicationDirPath;
qDebug()<<"currentPath:"<<currentPath;
// 3.返回上一级目录的路径
QDir dir(currentPath);
if (dir.cdUp()) {
QString dirPath = dir.absolutePath();
qDebug()<<"previous level:"<<dirPath;
} else {
qDebug() << "Failed to return to previous level";
}
}
2、控制台输出