Solved Problem with QSettings in QT 5.7
-
I used QSettings in QT 5.2. It saved settings in an ini file in a directory which has deny permission set for delete. I upgrade QT to 5.7 but it has problem with it. QSettings could not create ini file and some files like MyFileName.ini.hp(some numbers) and MyFileName.ini.lock.rmlock.rmlock..... will be created. If ini file existed before, program gets stuck in QSettings.sync() operation and again creates mentioned files.If I remove permission, program will work fine. I guess in QSettings 5.2 ini file is overwrited to previous file but in 5.7 it tries to delete previous and create new on. Is there any solution?
-
@MaryamTa I think the problem is that QSettings cannot remove the *.lock files when the app is closed. Next time you start the app it detects those files and thinks the settings are already in use. You should remove that access right restriction.
-
@jsulm Thanks for your quick reply. It seems to be true reason. But why every time it added a .rmlock and make new lock file?
And why it couldn't create ini file even if there is no file before?
At last, I really need to set the permission. Do you think there is another solution or not? -
@MaryamTa I don't know how QSettings.sync() is implemented, but you could take a look at the source code.
-
@jsulm I checked it but I couldn't find management on repeated lock files. Thanks anyway.
-
QSettings
tries to be smart. So it will use a lock file to provide scoping and synchronization for the actual settings file. This means it has to be able to create, lock, unlock and ultimately delete the lock file. Since you've removed the deletion it will fail (silently) when it has to clean up and will create a new lock file when the program's started again.