qt program deployed on mac. config file not writing when standalone app launched, works when run from within qt creator

筅森魡賤 提交于 2019-12-13 03:59:06

问题


I have a program that I have developed for mac osx. When the program is run from within Qt creator, a log file and a config.cfg file are created in the myapp.app/Contents/MacOS folder, alongside the executable. This is the correct behaviour, the program needs these files.

When I deploy the app to run standalone (by linking the required libraries using macdeploymentqt tool) the app launches and runs correctly however the log and config.cfg file do not get written to the myapp.app/Contents/MacOS folder and so settings can't be read in.

Is there anyway to get around this? Has anyone encountered this before?

Mitch


回答1:


osx will likely not allow you writing to your bundle location on installed apps, for security reasons and because it may conflict when multiple users are using your app.

To be cross platform, you could write instead to:

QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)

which resolves to

~/Library/Application Support/<APPNAME>

and

C:/Users/<USER>/AppData/Local/<APPNAME>

or equivalent on windows.




回答2:


You're never supposed to write to the application bundle, whether on Mac or on Windows. Even on Windows, it will not work if your user isn't an administrator. This idea last made sense on Windows 95 - not even on Windows NT. Don't do it.



来源:https://stackoverflow.com/questions/29327857/qt-program-deployed-on-mac-config-file-not-writing-when-standalone-app-launched

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!