Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qsettings different results

Tags:

c++

qt

I am using QSettings to try and figure out if an INI is valid.(using status() to check) I made a purposefully invalid INI file and loaded it in. The first time the code is called, it returns invalid, but every time after that, it returns valid. Is this a bug in my code?

like image 484
eyecreate Avatar asked Mar 28 '26 19:03

eyecreate


1 Answers

It's a Qt bug caused by some global state. Note that the difference in results happens whether or not you call delete on your QSettings object, which you should. Here's a brief summary of what happens on the first run:

  1. The result code is set to NoError.
  2. A global cache is checked to see if your file is present
  3. Your file isn't present the first time, so it's parsed on qsettings.cpp line 1530 (Qt-4.6.2)
  4. Parsing results in an error and the result code is set (see qsettings.cpp line 1552).
  5. The error result code is returned.

And the second run is different:

  1. The result code is set to NoError.
  2. A global cache is checked, your file is present.
  3. The file size and timestamp are checked to see if the file has changed (see qsettings.cpp line 1424).
  4. The result code is returned, which happens to be NoError -- the file was assumed to have been parsed correctly.
like image 55
Kaleb Pederson Avatar answered Apr 01 '26 08:04

Kaleb Pederson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!