如何查找Qt应用程序的安装目录

How to find the installation directory of a Qt application?

本文关键字:应用程序 安装 Qt 何查找 查找      更新时间:2023-10-16

我有一个基于Qt的应用程序,适用于Mac和Windows。 当用户安装软件时,它还会安装一个包含一堆HTML文档页面的文件夹。我如何找到程序安装的位置,以便当用户尝试从应用程序中打开帮助时,他们会被带到index.html.

我的程序安装在 Windows 和 Mac 的正常位置。 在Mac上,我的程序安装到/Users/username/Applications/MyProgram其中MyProgram是一个包含"MyProgram.app"和"Doc"文件夹的文件夹。

#ifdef Q_OS_MACX
    docPath = executablePath + "/Doc/index.html";
#elif Q_OS_WIN
    docPath = executablePath + "/Doc/index.html";
#endif
    QDesktopServices::openUrl(QUrl::fromLocalFile(docPath));

所以,我的终极问题是,executablePath应该是什么? 此外,这假设用户可以将程序安装在默认位置以外的其他位置,或者可以从快捷方式启动程序。

你应该使用:

QString QCoreApplication::applicationDirPath() [static]
相关文章: