Results 1 to 5 of 5

Thread: QSettings on QStrings

  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post QSettings on QStrings

    While the bool values on lines 6-7 are set up properly, it does not work for the QString on line 13. It returns an empty string, even when the appropiate key (here "General/lastshownwidgets") on the persistent media is set to a non-empty string. What am I missing ?

    Qt Code:
    1. globalSettings = new QSettings("./UnderClient.ini",QSettings::IniFormat,this);
    2. //globalSettings->setValue("foo","bar");
    3.  
    4. //Getting settings
    5. globalSettings->beginGroup("General");
    6. //line 6:
    7. minimizeToTrayOnStartUp = globalSettings->value("minimizetotrayonstartup",false).toBool();
    8. //line 7:
    9. autoRestoreLastWidgets = globalSettings->value("autorestorelastwidgets",false).toBool();
    10. if(autoRestoreLastWidgets) {
    11. //QString *temp = new QString(globalSettings->value("General/lastshownwidgets").toString());
    12. //lastShownWidgets = temp->split(',',QString::SkipEmptyParts);
    13. qDebug() << "restoring modules from last session (" << __PRETTY_FUNCTION__ << ")";
    14. //line 13:
    15. qDebug() << "got last shown widgets:" << globalSettings->value("lastshownwidgets").toString();
    16. lastShownWidgets = new QStringList(globalSettings->value("lastshownwidgets").toString().split(',',QString::SkipEmptyParts));
    17. //delete temp;
    18. }
    19. else {
    20. lastShownWidgets = new QStringList;
    21. }
    22. globalSettings->endGroup();
    23.  
    24. qDebug() << "minimizeToTrayOnStartUp:" << minimizeToTrayOnStartUp;
    25. qDebug() << "autoRestoreLastWidgets:" << autoRestoreLastWidgets;
    26. qDebug() << "lastShownWidgets:" << lastShownWidgets->join(",");
    27. //Write-back settings
    28. globalSettings->beginGroup("General");
    29. globalSettings->setValue("minimizetotrayonstartup",minimizeToTrayOnStartUp);
    30. globalSettings->setValue("autorestorelastwidgets",autoRestoreLastWidgets);
    31. globalSettings->setValue("lastshownwidgets",lastShownWidgets->join(","));
    32. globalSettings->endGroup();
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings on QStrings

    Could you post the relevant part of the .ini file?

  3. #3
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings on QStrings

    sure, here is it:
    [%General]
    autorestorelastwidgets=true
    lastshownwidgets=foo,bar
    minimizetotrayonstartup=false
    Last edited by OriginalCopy; 4th November 2007 at 00:39.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings on QStrings

    Try :
    [%General]
    autorestorelastwidgets=true
    lastshownwidgets="foo,bar"
    minimizetotrayonstartup=false

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings on QStrings

    I think there is no need to join/split the string list. Just store/restore it directly. Furthermore, QStringList is an implicitly shared class so there is no advantage in allocating it on the heap, it only makes things more complex..
    J-P Nurmi

Similar Threads

  1. QSettings, my own format of config-file
    By IPFreely in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 20:07
  2. Replies: 3
    Last Post: 18th October 2007, 08:07
  3. Using QSettings to populate a QComboBox
    By nbkhwjm in forum Newbie
    Replies: 16
    Last Post: 4th September 2007, 22:34
  4. QVariant, QList, QSettings
    By TheKedge in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2007, 15:50
  5. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26

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.