[Interest] Issue using QSettings INI format on Windows
Murphy, Sean
smurphy at walbro.com
Fri Feb 8 23:56:12 CET 2019
> Hi, just tested your example program in MSVC 2017 Qt 5.12.1 and it fails
> as well.
>
> But a simple fix is just to make sure that the QFile file isn't open at
> the same time as you write out the settings to it.
> I.e. in your example program, it suffices to move that first
> file.close(); up to just before the "// write out via QSettings" comment
> line is, then it runs flawlessly.
>
> But perhaps that's not possible to keep those writes separate in time in
> your "real" app that your porting?
Thanks for testing!
Yes, I discovered that issue as well, and then forgot to post a follow-up
here. Where I had trouble, and something I did differently in the real
app vs. the minimal example, is that the file I was trying to use to write
the settings to was a QTemporaryFile. I stumbled across the same fix you
did in the example, but that fix never seemed to work in my real app with a
QTemporaryFile. After testing, I believe that is because the QSettings
object is trying to open the associated settings file with write permissions,
and it isn't able to acquire them. In my example, it was because I already
had opened the file with write permissions (mistakenly thinking I needed
to do that before all the QSettings stuff). In my real app, I think that it
must be because QTemporaryFile holds a lock on the file so it can
remove it when the QTemporaryFile object goes out of scope, and
therefore the QSettings object gets an access error because the file is
already in use.
What I'm actually trying to accomplish is far more simple: I don't actually
want an INI file, I just want to get data that I've put into a QSettings object
written to a QString, in the INI file format. I couldn't see any other way to
do that than to write it out to a file, then read the file contents back into
a QString. So if you see a simpler solution for that, I'm open to suggestions!
In my real app, I've solved it by using removing the QTemporaryFile
object, and just letting QSettings do its thing, writing to a file. Then when
the file has been written, I read it back in to a QString, and delete the file
since I have no further use for it.
Sean
This message has been scanned for malware by Forcepoint. www.forcepoint.com
More information about the Interest
mailing list