【问题标题】:How to find the installation directory of a Qt application?如何找到 Qt 应用程序的安装目录?
【发布时间】:2013-09-27 18:15:44
【问题描述】:

我有一个适用于 Mac 和 Windows 的基于 Qt 的应用程序。当用户安装软件时,它还会安装一个包含一堆 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 应该是什么?此外,这假设用户可以将程序安装在默认位置以外的其他位置,或者可以从快捷方式启动程序。

【问题讨论】:

标签: c++ qt


【解决方案1】:

你应该使用:

QString QCoreApplication::applicationDirPath() [static]

【讨论】:

    猜你喜欢
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2023-03-27
    • 2023-02-06
    • 1970-01-01
    相关资源
    最近更新 更多