PDA

View Full Version : QSettings load and write problem in files



a.m.blub
4th April 2011, 06:56
Hi,
i have a little problem with my program.
I use Qsetting to load and write programsettings in a ini file.
I write a method to check settings in my file equal the current programsettings and if they are not equal to write the new settings in that file.

My problem when the Qsetting object can't write the settings in my file (settings in file and programsettings are different and file for test readonly) then say my method by second start that my filesettings and programsettings are equal. What is incorrect.

my method:


void Main::testsetting()
{
mysetting=new QSettings("test.ini",QSettings::IniFormat);
if(mysetting->value("testvalue").toString()==testvalue)
{ //second run
QMessageBox::information(this,"Check","Testvalue="+testvalue+ " is equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
}
else
{ //first run
QMessageBox::information(this,"Check","Testvalue="+testvalue+ " isn't equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
}
mysetting->setValue("testvalue",testvalue);
mysetting->sync();
if(mysetting->status() ==QSettings::NoError) QMessageBox::information(this,"Save","Save successful",QMessageBox::Ok);
else QMessageBox::information(this,"Save","Save error",QMessageBox::Ok);
delete mysetting;


}


The Qsetting class only use local in this method in my program.
I use Qt 4.7 under Linux and windows the same result.
Complete example in Attachments.6188

nightghost
4th April 2011, 10:31
I assume, that QSettings uses some kind of caching in order to be able to work normal if the settings file is readonly, since QSettings::sync is called automatically by Qt.

a.m.blub
11th April 2011, 06:10
that QtSetting cached the file is ok. But my problem is that all instance of Qsetting objects use this file are destroyed. And I create a new Qsetting Object with this file than use Qsetting a cached version of my config file that is not equal with the orginal file on disk. And this is not really good.

P.S. sorry for late answer