如何找到Qt应用程序的安装目录? [英] How to find the installation directory of a Qt application?
问题描述
我有一个基于Qt的应用程序,可在Mac和Windows上使用。当用户安装软件时,它还会安装一个包含一堆HTML文档页面的文件夹。我如何找到程序的安装位置,以便当用户尝试从应用程序中打开帮助时,将其带到 index.html
。
I have a Qt based application that works for both Mac and Windows. When the user installs the software it also installs a folder containing a bunch of HTML documentation pages. How I can find the location of the program's installation so that when the user tries to open Help from within the application, they're brought to index.html
.
我的程序安装在Windows和Mac的正常位置。在Mac上,我的程序安装到 / Users / username / Applications / MyProgram
,其中 MyProgram
是一个包含 MyProgram的文件夹。应用程序和文档文件夹。
My program installs in the normal locations for Windows and Mac. On Mac, my program installs to /Users/username/Applications/MyProgram
where MyProgram
is a folder containing "MyProgram.app" and the "Doc" folder.
#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 $ c $应该是什么c>是吗?此外,这假设用户可以在默认位置之外的其他位置安装程序,或者可以从快捷方式启动程序。
So, my ultimate question is, what should executablePath
be? Further, this assumes the user could install the program elsewhere besides the default location or that the program could be launched from a shortcut.
推荐答案
您应该使用:
QString QCoreApplication::applicationDirPath() [static]
这篇关于如何找到Qt应用程序的安装目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!