Results 1 to 3 of 3

Thread: Application directory path on linux (shortcut)

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Application directory path on linux (shortcut)

    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

  2. #2

    Default Re: Application directory path on linux (shortcut)

    Best way may be to use argv[0].

  3. #3
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Application directory path on linux (shortcut)

    Something like this should work under linux (not handling LONG paths though...):

    Qt Code:
    1. QString appPath()
    2. {
    3. // in linux, look up the /proc/<PID>/exe link.
    4. QString link;
    5. char spath[128];
    6. memset(spath,0,128);
    7. link.sprintf("/proc/%d/exe",getpid());
    8. if (readlink(link.toUtf8().constData(),spath,128)>0) return spath;
    9. return "";
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by bernt.ribbum; 11th March 2018 at 21:51. Reason: reformatted to look better

Similar Threads

  1. Change font directory path
    By Beppe in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 7th May 2010, 19:17
  2. adding directory to the path
    By threaderslash in forum Installation and Deployment
    Replies: 2
    Last Post: 2nd April 2009, 17:13
  3. how does Qt know the library path in LINUX
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 14th November 2008, 17:10
  4. Qt 4 current directory path
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2008, 18:58
  5. application directory path on mac
    By munna in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2007, 11:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.