我有一个适用于Mac和Windows的基于Qt的应用程序。当用户安装软件时,它还会安装一个包含一堆HTML文档页面的文件夹。如何找到程序的安装位置,以便当用户尝试从应用程序中打开帮助时,它们被带到index.html
。如何找到Qt应用程序的安装目录?
我的程序安装在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
应该是什么?此外,这假定用户可以在除默认位置之外的其他地方安装该程序,或者该程序可以从快捷方式启动。
可能重复[如何在Qt中获得可执行文件名](http://stackoverflow.com/questions/4515602/how-to-get-executable-name-in -qt) – syam
是不是QCoreApplication :: applicationDirPath(http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#applicationDirPath)正是你想要的吗? – Zlatomir