Results 1 to 5 of 5

Thread: Get Application Directory on MacOS return path with appName.app/Contents/MacOS

  1. #1
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Get Application Directory on MacOS return path with appName.app/Contents/MacOS

    I build cross-platform app that crate file for the user. To get full path I writing this code:
    Qt Code:
    1. QString fullPath = QCoreApplication::applicationDirPath();
    2. fullPath.append("/").append(filename);
    To copy to clipboard, switch view to plain text mode 

    After searching the file I found in the debugger that my file exist under <myAppName>.app/Contents/MacOS.

    The user haven't way to get those file (except via the terminal).

    The question: What should I do to receive "normal" path ? (I file aid to the user)
    • I not want use substring functions because same code should work well on Linux and Windows.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get Application Directory on MacOS return path with appName.app/Contents/MacOS

    Quote Originally Posted by AsfK View Post
    I build cross-platform app that crate file for the user. To get full path I writing this code:
    Qt Code:
    1. QString fullPath = QCoreApplication::applicationDirPath();
    2. fullPath.append("/").append(filename);
    To copy to clipboard, switch view to plain text mode 
    Well, that is the application's installation path. It is very likely that you can't create files in there (no permissions for normal users to create files in system locations).

    Quote Originally Posted by AsfK View Post
    The question: What should I do to receive "normal" path ? (I file aid to the user)
    Are you looking for QStandardPaths?



    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    AsfK (5th March 2014)

  4. #3
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Get Application Directory on MacOS return path with appName.app/Contents/MacOS

    Thank you Cheers
    I didn't know about this (I came from Windows 'world'..)
    I'll read about QSttandardPathes, thanks again!

    btw, do you know If I can do If Def in my code (If the app. run on Mac save where I can, else in the executable folder...) or if can I ask permissions ?
    Thanks,
    AsfK
    Last edited by AsfK; 5th March 2014 at 15:24.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get Application Directory on MacOS return path with appName.app/Contents/MacOS

    Quote Originally Posted by AsfK View Post
    Thank you Cheers
    I didn't know about this (I came from Windows 'world'..)
    Even true on Windows
    Well, on anything newer than Windows 98 and when not running with Administrator rights.

    Quote Originally Posted by AsfK View Post
    btw, do you know If I can do If Def in my code (If the app. run on Mac save where I can, else in the executable folder...)
    You can do that, e.g. when building using Q_OS_MAC, Q_OS_WINDOWS, etc. but I wouldn't recommend it until you really have to. Makes it a lot harder to maintain.

    Quote Originally Posted by AsfK View Post
    or if can I ask permissions ?
    Not sure what you mean by that?
    Checking if you can write a file? QFileInfo::isWritable()
    Ask the user for elevated rights? No cross-desktop way to do that and likely very unnecessary.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    AsfK (6th March 2014)

  7. #5
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Get Application Directory on MacOS return path with appName.app/Contents/MacOS

    Thank you very much !!!

Similar Threads

  1. QVideoWidget on macos blocks application, need help.
    By DavidXanatos in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2016, 20:19
  2. Embedding MacOS application in QtWidget
    By brainTech in forum Newbie
    Replies: 0
    Last Post: 3rd January 2013, 06:46
  3. Qt4 + C++ + MacOs + Path
    By zeeb100 in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2009, 10:23
  4. Application.app/Contents/MacOS file issue
    By sgmurphy19 in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2008, 10:03
  5. Replies: 8
    Last Post: 5th August 2008, 13:09

Tags for this Thread

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.