在 Qt 中,您可以使用 QCoreApplication::applicationDirPath() 函数来获取应用程序的当前目录。

示例代码:

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString currentDir = QCoreApplication::applicationDirPath();
    qDebug() << 'Current directory: ' << currentDir;

    return a.exec();
}

上述代码中,QCoreApplication::applicationDirPath() 函数返回一个 QString 类型的字符串,表示应用程序的当前目录。通过调用 qDebug() 函数将当前目录输出到控制台。

总结:

QCoreApplication::applicationDirPath() 函数是获取 Qt 应用程序当前目录的简便方法。通过使用此函数,您可以在程序中轻松访问应用程序的当前目录。

Qt 获取应用程序当前目录:简单易懂的示例代码

原文地址: https://www.cveoy.top/t/topic/qFvN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录