PDA

View Full Version : Application directory path on linux (shortcut)



MadBear
4th October 2010, 14:58
Greetings,
I would like to know how to access application directory in linux if I run application through shortcut. QApplication::applicationDirPath(), doesn't give right path.

Regards,
MadBear

vincent38
5th November 2010, 16:30
Best way may be to use argv[0].

bernt.ribbum
11th March 2018, 21:18
Something like this should work under linux (not handling LONG paths though...):


QString appPath()
{
// in linux, look up the /proc/<PID>/exe link.
QString link;
char spath[128];
memset(spath,0,128);
link.sprintf("/proc/%d/exe",getpid());
if (readlink(link.toUtf8().constData(),spath,128)>0) return spath;
return "";
}