[solved] Mavericks File Permission Problem
-
Hi there,
building my app under Mavericks, Qt 5.2rc with xcode 5.0.2, compiles and runs fine when started from QtCreator.
I do macdeployqt on the .app fileThen I try to run it by double clicking it in finder. It opens a window, but that window stays black. This is in fact expected behavior for my app, if it can't find or open required resource files.
When I run it from terminal "open My.app", same results, black window in my face.
However, when I go "sudo open My.app" it runs just fine, loads all the resource files and displays.So this must be some kind of file permission issue with Mavericks / Qt?
I never had this on OSX 10.8 down to 10.6.8Any ideas?
-
Hi,
What kind of application is it (Widget, QML) ? What are the files you are opening ? When you say they exist in the same folder, which folder are you talking about ?
-
It's a Widget application
from the .pro file:@
QT += opengl
QT += widgets
@the files I'm opening are xml data (Settings.xml) and image and sound files. (.tga, .ogg)
Just the folder, in which the .app file lives, it also contains the resource files (all the xml , tga, ogg files)
[top application folder, can be placed anywhere] ->{ lots of files, My.app, some more folders with more files}
the app loads "lots of files" and also "some more files" in "some more folders". This works fine if I'm sudo, but not if I'm a normal user. Then it won't let the app open the files. I don't know why..
-
Did you run macdeployqt on your application bundle ?
-
And that's correct, you don't need to run it in sudo mode.
Can you create a minimal example program that shows the problem ?
-
I made a minimal code version of the problem I have.
Compiled with Qt 5.2rc and qtmacdeployed on Mavericks. Source included.
When launched it will attempt to open one file ("Controls.xml"). If success it will open a QMessageBox "Success"
otherwise a QMessageBox with "Fail"On Mavericks:
-running this as sudo or from QtCreator -> success
-running it from finder -> fails.To test it, get it here ( couldn't figure out how to attach this zip here..):
https://drive.google.com/file/d/0B2hpkmDPq1oaRUEyYmdYWEUyV2s/edit?usp=sharing
-
Just tested it (Had to rebuild your sources, OS X told me It could not open the app because it was from an unidentified developer)
The problems come from the fact that you try to open Controls.xml without giving the path to the file so it's relative to the "current path" of the application. In Mavericks, Apple has modified what working directory it gives to the application and e.g. calling it from the console (./My.app/Contents/MacOS/My) or from finder, will not give the same result, thus your file is really not found -
For the sake of testing, you should give the absolute path e.g. "/Users/your_user_name/path_to/Controls.xml"
-
Just tested it and it works fine with “/Users/your_user_name/path_to/Controls.xml”
both from QtCreator and from Finder. So that's great for testing..But I can't use that for deployment. And the ../../../ thing doesn't seem to work..
when I use
"../../../Controls.xml"
as path (relative to the executable) it works, when running from QtCreator but it doesn't work via double click starting from finder.What could be the solution?
-
The working dir is set by the parent process. You'll get different result if you launch from the Finder or the terminal. This is not a reliable way to find your resources.
Look at QCoreApplication::applicationDirPath or QStandardPaths::locate.