qt程序部署在mac上。配置文件在独立应用程序启动时不写入,在qt创建者中运行时工作 [英] qt program deployed on mac. config file not writing when standalone app launched, works when run from within qt creator

查看:337
本文介绍了qt程序部署在mac上。配置文件在独立应用程序启动时不写入,在qt创建者中运行时工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我为Mac osx开发的程序。当程序从Qt创建者中运行时,将在可执行文件中的myapp.app/Contents/MacOS文件夹中创建一个日志文件和一个config.cfg文件。这是正确的行为,程序需要这些文件。



当我部署应用程序以独立运行(通过使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆