qt程序部署在mac上。配置文件在独立应用程序启动时不写入,在qt创建者中运行时工作 [英] qt program deployed on mac. config file not writing when standalone app launched, works when run from within qt creator
问题描述
当我部署应用程序以独立运行(通过使用macdeploymentqt工具链接所需的库)应用程序启动并运行但是,日志和config.cfg文件不会被写入myapp.app/Contents/MacOS文件夹,因此无法读入设置。
是否有反正要解决这个问题有没有人遇到过?
Mitch
出于安全考虑,不允许您在安装的应用程序上写入您的软件包位置,并且因为在多个用户使用您的应用程序时可能会发生冲突。
为了跨平台,您可以写入:
QStandardPaths :: writableLocation(QStandardPaths :: AppLocalDataLocation)
/ pre>
其中解决了
〜/库/应用程序支持/< APPNAME>
和
C:/用户/<使用者> /应用程序数据/本地/< APPNAME>
或相当于Windows。
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
解决方案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.
这篇关于qt程序部署在mac上。配置文件在独立应用程序启动时不写入,在qt创建者中运行时工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!