关于Qt QSettings写入ini的疑问

老坛酸菜 2022-03-08 11:24:16

频繁对一个ini文件setValue操作,会生成一个xx.ini.lock以及一个xx.ini.VCAzFK的两个中间文件,VCAzFK保存的是最新的写入数据,当我关闭程序时,这两个文件还存在,这就导致ini里面的数据不是最新,重启程序从ini获取到数据就不对,请问有什么办法刷新数据么?

...全文
335 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-西门吹雪 2022-03-08
  • 打赏
  • 举报
回复
QSettings can safely be used from different processes (which can be different instances of your application running at the same time or different applications altogether) to read and write to the same system locations, provided certain conditions are met. For QSettings::IniFormat, it uses advisory file locking and a smart merging algorithm to ensure data integrity. The condition for that to work is that the writeable configuration file must be a regular file and must reside in a directory that the current user can create new, temporary files in. If that is not the case, then one must use setAtomicSyncRequired() to turn the safety off.

使用setAtomicSyncRequired()关闭安全设置这两个文件应该就没了,但是对一个文件的修改应该是1个修改多个读,如果多个修改应该加锁,保证数据不脏

-西门吹雪 2022-03-08
  • 举报
回复
@-西门吹雪 QSettings can safely be used from different processes (which can be different instances of your application running at the same time or different applications altogether) to read and write to the same system locations, provided certain conditions are met. For QSettings::IniFormat, it uses advisory file locking and a smart merging algorithm to ensure data integrity. The condition for that to work is that the writeable configuration file must be a regular file and must reside in a directory that the current user can create new, temporary files in. If that is not the case, then one must use setAtomicSyncRequired() to turn the safety off.
老坛酸菜 2022-03-09
  • 举报
回复
@-西门吹雪 多谢解答,确实实时修改文件是一个很傻 办法。后面修改了做法,需要的时候才去写

16,817

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧