How to find the installation directory of a Qt application?
Asked Answered
H

1

11

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.

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));

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.

Heterothallic answered 27/9, 2013 at 18:15 Comment(2)
possible duplicate of how to get executable name in QtDrab
Isn't QCoreApplication::applicationDirPath ( qt-project.org/doc/qt-5.0/qtcore/… ) do exactly what you want?Supplementary
A
24

You should use:

QString QCoreApplication::applicationDirPath() [static]
Auger answered 27/9, 2013 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.