我有一个基于Qt的应用程序,适用于Mac和Windows.当用户安装软件时,它还会安装包含大量HTML文档页面的文件夹.我如何找到程序安装的位置,以便当用户尝试从应用程序中打开"帮助"时,它们会被带到index.html.
我的程序安装在Windows和Mac的正常位置.在Mac上,我的程序安装到/Users/username/Applications/MyProgram其中MyProgram是包含"MyProgram.app"和"文档"文件夹中的文件夹.
#ifdef Q_OS_MACX
docPath = executablePath + "/Doc/index.html";
#elif Q_OS_WIN
docPath = executablePath + "/Doc/index.html";
#endif
QDesktopServices::openUrl(QUrl::fromLocalFile(docPath));
Run Code Online (Sandbox Code Playgroud)
所以,我的最终问题是,应该executablePath是什么?此外,这假设用户可以在除默认位置之外的其他地方安装程序,或者可以从快捷方式启动程序.
lpa*_*app 20
你应该使用:
QString QCoreApplication::applicationDirPath() [static]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8704 次 |
| 最近记录: |