Results 1 to 9 of 9

Thread: Save a QStringList to arrey in QSettings

  1. #1
    Join Date
    Mar 2010
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Save a QStringList to arrey in QSettings

    How do i save a QStringList to a arrey in Settings?

    Qt Code:
    1. QString myvalue; //This have value from before.
    2.  
    3. settings settings(Me, App);
    4. settings.beginGroup("ServerManager");
    5. settings.beginWriteArray("ServerItems");
    6. settings.setValue("ServerItem", myvalue);
    7. settings.endArray();
    8. settings.engGroup();
    To copy to clipboard, switch view to plain text mode 

    Can anyone help me?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Save a QStringList to arrey in QSettings

    Yes, but what do you want to know what the docs are not providing? Isn't there a good example: QSettings::beginWriteArray()?

    EDIT: And a QStringList is (almost) nothing else than QList<QString>

  3. #3
    Join Date
    Mar 2010
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Save a QStringList to arrey in QSettings

    As this:

    Qt Code:
    1. QStringList myvalue;
    2.  
    3. QSettings settings;
    4. settings.beginWriteArray("ServerItems");
    5. for (int i = 0; i < myvalue.size(); ++i) {
    6. settings.setArrayIndex(i);
    7. settings.setValue("ServerItem", list.at(i).myvalue);
    8. }
    9. settings.endArray();
    To copy to clipboard, switch view to plain text mode 

    Please correct if i am wrong...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Save a QStringList to arrey in QSettings

    is myvalue == list? How do you normally access a string from your string list. How would you normally loop through your string list?

  5. #5
    Join Date
    Mar 2010
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Save a QStringList to arrey in QSettings

    Its a QStringList with 4 values (strings). Is the code correct?

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Save a QStringList to arrey in QSettings

    Damn, NO, it's not correct. Try it and you see it will not work. And all necessary hints I have already given.

    (And for future you should may be take our Newbie section!)

  7. #7
    Join Date
    Mar 2010
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Save a QStringList to arrey in QSettings

    Well, i am ask. Can you please help me get it work?

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Save a QStringList to arrey in QSettings

    Please, next time use the newbie section. And I wont provide the code.

    When you have this string list:
    Qt Code:
    1. list << "read" << "the" << "documentation";
    To copy to clipboard, switch view to plain text mode 
    How would you iterate through the items and show them using qDebug()? All infos you can find here: QStringList.

    If you now that, just combine it with the array writing.

  9. #9
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Save a QStringList to arrey in QSettings

    Quote Originally Posted by halvors View Post
    As this:

    Qt Code:
    1. QStringList myvalue;
    2.  
    3. QSettings settings;
    4. settings.beginWriteArray("ServerItems");
    5. for (int i = 0; i < myvalue.size(); ++i) {
    6. settings.setArrayIndex(i);
    7. settings.setValue("ServerItem", list.at(i).myvalue);
    8. }
    9. settings.endArray();
    To copy to clipboard, switch view to plain text mode 

    Please correct if i am wrong...
    Where is `list` defined? Even in the documentation, it is the same but I don't understand why list is not defined. It sure come up as undeclared identifier and doesn't build.

    In my case I only want to save QStringArray to QSettings, how to do that?

Similar Threads

  1. Replies: 2
    Last Post: 2nd September 2009, 13:36
  2. QSettings to save multiple "workspaces"
    By Bitruder in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2009, 21:56
  3. Save enums in QSettings
    By redhat in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2009, 11:22
  4. QSettings does not save...
    By mtrpoland in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2007, 12:15
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

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.