roundtheworld
roundtheworld

Reputation: 2795

How to find the installation directory of a Qt application?

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.

Upvotes: 12

Views: 12175

Answers (1)

László Papp
László Papp

Reputation: 53173

You should use:

QString QCoreApplication::applicationDirPath() [static]

Upvotes: 25

Related Questions