温馨提示×

qt获取当前路径的方法是什么

qt
小亿
119
2023-11-24 10:48:22
栏目: 编程语言

要获取当前路径,可以使用QCoreApplication::applicationDirPath()方法。该方法返回一个QString,表示应用程序的当前路径。下面是一个示例代码:

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    QString currentPath = QCoreApplication::applicationDirPath();
    qDebug() << "Current path: " << currentPath;
    
    return a.exec();
}

运行上述代码,会打印出当前路径。

0