Get app dir of application on Mac OS sierra
-
Hi there,
I have trouble with the QApplication::applicationDirPath() and QDir::currentPath() functions.On some computers this function return strange path:
/private/var/folders/z0/lp84cp8d4831k8519j46qyt00000gn/T/AppTranslocation/D2CXXC75-CXX3-4689-8XXA-CCD4641072XX/d/mcercle.app/Contents/MacOS
The correct path is
/users/theuser/documents/mcercle...
Why Qt can't find where is the application ?
I found this http://doc.qt.io/qt-5/osx-issues.html#macos-native-api-access but on this page "QCoreApplication::applicationDirPath() can be used to determine the path of the binary within the bundle."thanks!
-
This is part of a change to the way Gatekeeper works on Sierra - apps that aren't signed are moved to a randomized location before execution. So the path returned really is where your executable is, at the moment it is running. It's called "App Translocation."
-
@Chris-Hennes Ok thanks for this information!
But is there a solution to get some files where is really my application ...whitout QApplication::applicationDirPath() ? :( -
Based on what I have read the 'Translocation' (lol) is only done if you are running an app from an archive like a DMG file. The purpose of this is to prevent a signed app from loading unsigned executables that are distributed along with the app. The relative path option would not be usable to give you the true location of the app which prevents this kind of attack.
So, it is doubtful you will be able to find a work around to this.
I expect that the relative path still works within the app container (folder). If you need to include some data or other files with your app why not put them inside the app (not alongside)?
-
@cfdev You can put them into your executable. See http://doc.qt.io/qt-5/resources.html