PDA

View Full Version : QSettings does not save...



mtrpoland
27th August 2007, 22:15
I have encountered an obstacle. I use QSettings to store an URL address (as QString) and a QStringList which is then used in creating a List of my MTR::Record objects.

I save my settings in a destructor of my main QWidget subclass.

MyWidget::~MyWidget() {
QVariant var(packRecords(rekordyLokalne));
settings->setValue("rekordyLokalne",var);
//foreach(QString str, var.toStringList()) qDebug() << str;
//foreach(QString str, settings->value("rekordyLokalne").toStringList()) qDebug() << str;
//qDebug() << settings->value("rekordyLokalne").toStringList().count();
}

where

QStringList packRecords(QList<MTR::Records> &);
is used to serialize a list of my objects to a list of strings.

Inside a program I manually make a few entries to the rekordyLokalne.

I expect the code in destructor to save all the data needed but only data attached to "conciseDataURL" is saved. I know it as I check in a destructor (after writing data) and code below (that is used in constructor to read data) the number of items stored in QStringList attached to "rekordyLokalne" key.
Debug code in destructor says for example 6 entries, while the code from constructor (afer reopening the program) says that there are 0 entries.
It puzzles me why there are problems with QStringList and everything is okay with QString.

Heres a method used once in the constructor:

void MyWidget::DownloadData() {
settings = new QSettings("MTR","MTR::Mastermind 1.0 PL");
if(settings->value("conciseDataURL") == QVariant())
settings->setValue("conciseDataURL", QVariant("ftp://ftp.mjakobczyk.pl/mastermind.konfig"));
else
settings->setValue("conciseDataURL", settings->value("conciseDataURL"));

QString urlek = settings->value("conciseDataURL").toString();
QStringList sl = settings->value("rekordyLokalne").toStringList();
//qDebug() << settings->value("rekordyLokalne").toStringList().count();

}

jacek
27th August 2007, 22:20
Do you destroy settings object or call QSettings::sync() anywhere in your code?

mtrpoland
28th August 2007, 12:15
nope, I do not
Thanks for the hint.