Hi all,

I would like to store some data structured as an array. That's working, and my settings file contains something like:
Qt Code:
  1. [blogAccounts]
  2. 1\accountName=Test 1
  3. 1\userName=Mike
  4. 1\userPassword=secret
  5. 2\accountName=Test 2
  6. 2\userName=Mike
  7. 2\userPassword=secret
  8. size=2
To copy to clipboard, switch view to plain text mode 

Now I use this code to remove the first item, and let's assume that the currentAccountName contains the first entry of the array:
Qt Code:
  1. ...
  2. // Ok, we need to find the right account...
  3. QSettings settings("MKrueger", "MKBlog");
  4. int size = settings.beginReadArray("blogAccounts");
  5. bool didRemove = false;
  6. for (int i = 0; i < size; ++i)
  7. {
  8. // Select the data set
  9. settings.setArrayIndex(i);
  10. // Now compare the account name with the one selected...
  11. if (_currentAccountName == settings.value("accountName").toString())
  12. {
  13. // This is the one we need to remove...
  14. settings.endArray();
  15. // Now reopen the settings for writing...
  16. settings.beginWriteArray("blogAccounts");
  17. // select the desired account again
  18. settings.setArrayIndex(i);
  19. // and now remove it...
  20. settings.remove("");
  21. didRemove = true;
  22. break;
  23. }
  24. }
  25. settings.endArray();
  26.  
  27. if (false == didRemove)
  28. return; // Unable to remove account
To copy to clipboard, switch view to plain text mode 

The result in my settings file is this:
Qt Code:
  1. [blogAccounts]
  2. 2\accountName=Test 2
  3. 2\userName=Mike
  4. 2\userPassword=secret
  5. size=1
To copy to clipboard, switch view to plain text mode 

If I now try to load the remaining account it fails. I suspect because the prefix is still 2 and not 1. Would that assumption be correct?
If so, how should I remove an item correctly? Do I have to remove the complete array and then write it out again?

Thanks...