Results 1 to 8 of 8

Thread: QSettings - beginReadArray not working

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSettings - beginReadArray not working

    Hi all,

    I have a suspicion, that the beginReadArray method of Qt 4.1 is not working. I use the QSettings sample to save the window size and location and that's working. Now I wanted to save account information as an array. I see the data in stored in the applications configuration file, but when I try to load the data using the above method, the size returned is alway's 0.

    Anybody else see this?

    Regards,
    Mike

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings - beginReadArray not working

    I used array reading capabilities and it worked fine. Could you provide a minimum compilable example which reproduces the problem?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings - beginReadArray not working

    I will do tonight. Hope you're around. Thx

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings - beginReadArray not working

    Btw., did you use it under Windows or Linux? Maybe there is a difference if you use it with the Registry or a flat file under Linux. I also use all defaults - no custom storage handler...

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings - beginReadArray not working

    Quote Originally Posted by Mike
    Btw., did you use it under Windows or Linux? Maybe there is a difference if you use it with the Registry or a flat file under Linux. I also use all defaults - no custom storage handler...
    All defaults, and there is no difference between platforms in this code. Array reading is a "high-level" (platform independent) call. It then calls lower-level (platform dependent) methods to read the item itself.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings - beginReadArray not working

    hmmm... I guess you are right. My little test app seems to work correctly:

    Qt Code:
    1. #include <QSettings>
    2. #include <QString>
    3.  
    4. void saveSettingsArray()
    5. {
    6. QSettings settings("MKrueger", "SettingsTest");
    7. settings.beginWriteArray("blogAccounts");
    8.  
    9. for (int i = 0; i <= 2; ++i)
    10. {
    11. // This is a new account, we will save it to the end of the list ...
    12. settings.setArrayIndex(i);
    13. settings.setValue("accountName", "Test-Account: " +
    14. QString::number(i));
    15. settings.setValue("hostName", "www.michael-krueger.org");
    16. }
    17. settings.endArray();
    18. }
    19.  
    20. void loadSettingsArray()
    21. {
    22. QSettings settings("MKrueger", "SettingsTest");
    23. int size = settings.beginReadArray("blogAccounts");
    24.  
    25. for (int i = 0; i < size; ++i)
    26. {
    27. // Select the data set
    28. settings.setArrayIndex(i);
    29. //
    30. QString temp("accountName: ");
    31. temp += settings.value("accountName").toString();
    32. qDebug(temp.toAscii());
    33. temp = "hostName: ";
    34. temp += settings.value("hostName").toString();
    35. qDebug(temp.toAscii());
    36. }
    37. settings.endArray();
    38. }
    39.  
    40. int main(int /*argc*/, char /**argv[]*/)
    41. {
    42. saveSettingsArray();
    43. //
    44. loadSettingsArray();
    45. return 0;
    46. }
    To copy to clipboard, switch view to plain text mode 

    The app above does work as expected. I need to double check my application.

    The output is correctly:
    Qt Code:
    1. micha@helium:~/develop/QSettingsTest> ./QSettingsTest
    2. accountName: Test-Account: 0
    3. hostName: www.michael-krueger.org
    4. accountName: Test-Account: 1
    5. hostName: www.michael-krueger.org
    6. accountName: Test-Account: 2
    7. hostName: www.michael-krueger.org
    8. micha@helium:~/develop/QSettingsTest>
    To copy to clipboard, switch view to plain text mode 

    ... very strange, very strange ...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings - beginReadArray not working

    Check if settings are correct in the stored file (if you use files).

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings - beginReadArray not working

    I think I found the problem. I think that I did set the array index wrong. That could have caused my problem I guess. I will check that again. The file did contain my settings. Writing must have been ok, reading not.

Similar Threads

  1. QSettings and QGLWidgets
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2008, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.