Question

I use QSettings to save and load parameters to/from an ini file using Linux:

write:

QSettings settings("setup.ini", QSettings::IniFormat);
settings.beginGroup("Setup_Parameter");
settings.setValue("Parameter1",parameter1_value);
settings.sync();
settings.endGroup();

read:

QSettings settings("setup.ini", QSettings::IniFormat);
settings.beginGroup("Setup_Parameter");
parameter1_value = settings.value("Parameter1","0").toInt();
settings.endGroup();

The setup.ini works fine, while the system is on. If i reboot my system by switching power off and on again, the setup.ini file gets completely empty sometimes. I would say in 3 out of 5 trys.

I already tryed saving the file in application and root/Settings path. As well as copying the file after writing it, but then also the copy is empty after power off and on.

Why does the setup.ini File looses its content? It needs to keep the parameters while restart.

Was it helpful?

Solution

A sync() was required after the write function:

QSettings settings("setup.ini", QSettings::IniFormat);
settings.beginGroup("Setup_Parameter");
settings.setValue("Parameter1",parameter1_value);
settings.endGroup();
settings.sync();
sync();

OTHER TIPS

I am experiencing the same problem. My QSettings file gets wiped out sometimes after a power reset. The file remains, but it is zero bytes in size. The QT application is running on Debian Squeeze on an ARM processor. The filesystem, OS, and application are all located on a 4G SD Card.

I've modified the application to call the sync function after any change to the Settings file. But we had a power reset last night and one of the units (we have about 60 running) lost its settings. We're running QTEmbedded-4.8.2, and I am at a loss how to fix this.

We have fixed the same problem calling 'sync' linux command after the 'sync' function of QSettings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top