Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.6
-
None
Description
- Open settings file in INI format and write to it the filled QStringList with beginWriteArray()/endArray() functions. Write for example different 10 strings.
- Open INI file to read in third party text editor and watch all 10 strings written. Variable "size=10" will be written at the end of array. That's right.
- Open in code this array and read array to QStringList with beginReadArray()/endArray() functions.
- Remove some (for example 5) random lines from this QStringList.
- Write it again with same method as used in step 1. Write only 5 rest lines.
- Open INI again in text editor - you will see 10 (not 5) lines in array. First 5 will correspond to lines written in step 5. Next 5 will be "tail" of 10 lines written in step 1. And you will see "size=5" at the end of array.
That means - if you will write bigger and bigger arrays - then QSettings engine will collect and carry garbage in INI file. Once you wrote 1000 items - next time INI file will keep all 1000 items even if only 1 item will be used in all next job. And QSettings will read and write 1000 items again and again. That means - QSettings reads ENTIRE array in beginReadArray() function but then does not CLEAR the rest of array after "size" items. And later when writing array with beginWriteArray() it writes entire buffer but not only it's size() items.
Solution - 1) after entire array was read to internal QSettings buffer then all items with indexes greater or equal to "size" must be removed 2) before writing array internal QSettings buffer must be reduced to item with largest changed index.