Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the installation directory of a Qt application?

Tags:

c++

qt

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.

like image 370
roundtheworld Avatar asked Sep 27 '13 18:09

roundtheworld


1 Answers

You should use:

QString QCoreApplication::applicationDirPath() [static]
like image 135
lpapp Avatar answered Oct 28 '22 02:10

lpapp