QSettings:移动/更改现有 QSettings 对象的范围/位置
我正在编写一个程序,它将所有设置存储在 QSettings 对象中。现在我想为用户提供随时更改数据存储位置的选项。显然,QSettings 不提供更改其范围并将其所有数据复制到新位置的功能,例如从注册表复制到 %APPDATA% 中的文件。
据我所知:
- QSettings::setPath() 在构造之前使用,不会影响现有对象。
- 复制操作员是私有的。我可以子类化 QSettings 但我担心在复制操作期间由于其他线程同时写入而丢失设置。
如何将我的程序设置即时移动并保留到新位置?如果可能的话,我真的很想用 QSettings 来实现这一点。
I am writing a program which stores all its settings in a QSettings object. Now I would like to give the user the option to change the storage location of his data at any time. Apparantly QSettings does not provide the ability to change its scope and copy all its data to a new location, say from the registry to a file in %APPDATA%.
What I know:
- QSettings::setPath() is used before construction and doesn't affect existing objects.
- The copy operator is private. I could subclass QSettings but I am afraid of settings being lost during the copy operation because of other threads writing simultaneously.
How do I move and retain my program settings on the fly to a new location? I'd really like to achieve this with QSettings if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

线程安全的单例包装类是一个选择吗?
Would a thread-safe singleton wrapper class be an option?