View Full Version : QSettings load and write problem in files

4th April 2011, 07:56
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);
{ //second run
QMessageBox::information(this,"Check","Testvalue="+testvalue+ " is equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
{ //first run
QMessageBox::information(this,"Check","Testvalue="+testvalue+ " isn't equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
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

4th April 2011, 11: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.

11th April 2011, 07: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