温馨提示×

qt怎么获取当前路径

qt
小亿
504
2023-12-15 11:55:06
栏目: 编程语言

在Qt中,可以使用QCoreApplication::applicationDirPath()方法获取当前应用程序的路径。该方法返回一个QString对象,表示应用程序所在的文件夹路径。

示例如下:

#include <QCoreApplication> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString currentPath = QCoreApplication::applicationDirPath(); qDebug() << "当前路径:" << currentPath; return a.exec(); } 

运行以上代码,将会打印出当前应用程序的路径。

0