Get app dir of application on Mac OS sierra
-
wrote on 2 Mar 2017, 14:55 last edited by
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!
-
wrote on 2 Mar 2017, 15:45 last edited by
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."
-
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."
wrote on 3 Mar 2017, 08:20 last edited by@Chris-Hennes Ok thanks for this information!
But is there a solution to get some files where is really my application ...whitout QApplication::applicationDirPath() ? :( -
wrote on 3 Mar 2017, 13:26 last edited by
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)?
-
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)?
-
@Rondog ...If you need to include some data or other files with your app why not put them inside the app (not alongside)?...
you mean put the files into in the app bundle ?
@cfdev You can put them into your executable. See http://doc.qt.io/qt-5/resources.html
1/6