PDA

View Full Version : QSettings on QStrings



OriginalCopy
3rd November 2007, 23:22
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 ?


globalSettings = new QSettings("./UnderClient.ini",QSettings::IniFormat,this);
//globalSettings->setValue("foo","bar");

//Getting settings
globalSettings->beginGroup("General");
//line 6:
minimizeToTrayOnStartUp = globalSettings->value("minimizetotrayonstartup",false).toBool();
//line 7:
autoRestoreLastWidgets = globalSettings->value("autorestorelastwidgets",false).toBool();
if(autoRestoreLastWidgets) {
//QString *temp = new QString(globalSettings->value("General/lastshownwidgets").toString());
//lastShownWidgets = temp->split(',',QString::SkipEmptyParts);
qDebug() << "restoring modules from last session (" << __PRETTY_FUNCTION__ << ")";
//line 13:
qDebug() << "got last shown widgets:" << globalSettings->value("lastshownwidgets").toString();
lastShownWidgets = new QStringList(globalSettings->value("lastshownwidgets").toString().split(',',QString::SkipEmptyParts));
//delete temp;
}
else {
lastShownWidgets = new QStringList;
}
globalSettings->endGroup();

qDebug() << "minimizeToTrayOnStartUp:" << minimizeToTrayOnStartUp;
qDebug() << "autoRestoreLastWidgets:" << autoRestoreLastWidgets;
qDebug() << "lastShownWidgets:" << lastShownWidgets->join(",");
//Write-back settings
globalSettings->beginGroup("General");
globalSettings->setValue("minimizetotrayonstartup",minimizeToTrayOnStartUp);
globalSettings->setValue("autorestorelastwidgets",autoRestoreLastWidgets);
globalSettings->setValue("lastshownwidgets",lastShownWidgets->join(","));
globalSettings->endGroup();


Thank you in advance

jacek
4th November 2007, 00:10
Could you post the relevant part of the .ini file?

OriginalCopy
4th November 2007, 00:30
sure, here is it:

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

jacek
4th November 2007, 00:48
Try :
[%General]
autorestorelastwidgets=true
lastshownwidgets="foo,bar"
minimizetotrayonstartup=false

jpn
4th November 2007, 10:57
I think there is no need to join/split the string list. Just store/restore it directly. Furthermore, QStringList is an implicitly shared (http://doc.trolltech.com/4.3/shared.html) class so there is no advantage in allocating it on the heap, it only makes things more complex..