Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCoreApplication::applicationDirPath()..gives different results on Win7 and Mac??
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 16.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PSI-lbc
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PSI-lbc
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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 :)

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved