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?
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.