QCoreApplication::applicationDirPath()..gives different results on Win7 and Mac??



  • Trying to access a file in a subdirectory from where the executable is located.

    The code reads as:

    @QString duh = QCoreApplication::applicationFilePath() + "/" + "Help" + "/" + "myHelp.html";@

    Running Qt Creator on Windows "duh" is equal to:

    @/Users/PSI/Projects/QT SFA 4.7.2/SFA-build-desktop/SFA.app/Help/myHelp.html@

    Running Qt Creator on Mac "duh" is equal to:

    @/Users/PSI/Projects/QT SFA 4.7.2/SFA-build-desktop/SFA.app/Contents/MacOS/SFA/Help/myHelp.html@

    For whatever reason, the Mac version inserts "/Contents/MacOS/SFA/" after output for the call to QCoreApplication::applicationFilePath()" where the call on the Windows code does not.

    Is this a Mac idiosyncrasy or am I missing a Mac setting that will give the actual directory that the executable is in??

    I've tried running the code through Creator and the "/Contents/MacOS/SFA/" is added resulting that the file I'm trying to load is not found. Same Result "double clicking" on the Mac executable outside of Creator.

    On Windows the call to "QCoreApplication::applicationFilePath() work as "expected", resulting in the file being loaded.

    Is there another method to get the "root directory" of the application that works regardless of platform and regardless of whether it a dev or runtime environment?


  • Moderators

    I guess that is where the mac puts the actual executable. Mac puts everything belonging to a program into one directory and then makes the user perceive that as the application in its UI.



  • application file path it the path to the actual executable.

    On the Mac, applications are packed as so called application bundles. Technially, these are just directories in the file system, with a suffix ".app". The Finder treats those specially decorated directories as a single file. There are more types of bundles on the Mac. The layout of those are defined by apple in "Bundle Programming Guide":http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html

    The base line is: the actual executable path is MyFancApplication.app/Contents/MacOS/MyFancyApplication



  • that is where the mac puts the actual executable
    The Finder treats those specially decorated directories as a single file.

    Thanks guys.

    Aaahhhh, lightblub goes on. Looking at the "app package" it appeared like it was the ".exe".

    When I double clicked on the "app package", the app ran. If I right click on it, and select "show package contents", the package "directory" is displayed in a "finder like" dialog window that you can drag files or directories into.

    Problem solved. Just a Mac learning curve.



  • Just for some nitpicking: the new window actually is a Finder window :-) The same works for (double) clicking on a folder while holding the cmd-key.

    Ah, BTW: The nice thing is of course, the Qt creates the app bundle for you :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.