In my application, sometimes I need to find out the path of the application executable. I use QApplication::applicationFilePath()
and it works fine. But when I distribute my application as AppImage on Linux, this breaks. It returns the path where the running AppImage was mounted, e.g. /tmp/.mount_MyAppxyzabc/MyApp
. But I would need to get the path of the AppImage itself, e.g. /home/vlad/MyApp/MyApp.AppImage
. Is this possible to obtain from inside the running application?
Asked
Active
Viewed 546 times
1

HiFile.app - best file manager
- 7,273
- 2
- 32
- 80
2 Answers
2
I quickly found the answer and I will leave it here for others. At least for AppImages deployed by linuxdeployqt
(not sure about other AppImages), the path to the appimage is in environment variable $APPIMAGE.
So in my code I use:
QString appImagePath = QProcessEnvironment::systemEnvironment().value(QStringLiteral("APPIMAGE"));
The returned string however ends with path separator '/' so I need to remove it.

HiFile.app - best file manager
- 7,273
- 2
- 32
- 80
0
The code above doesn't work for me. appImagePath is set to an empty QString. Also, the following:
QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
QStringList tt = env.keys();
QFile outFile("./debug.txt");
outFile.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&outFile);
for (QStringList::iterator it = tt.begin(); it != tt.end(); ++it)
out << *it << " " << env.value(*it) << endl;
outFile.close();
works for me in my release build, but doesn't in the appImage
This is on Linux.
Thanks.
-
If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/31011685) – zephryl Feb 14 '22 at 04:25