PDA

View Full Version : Qtopia-4.2 Restoring the Saved Values for QComboBoxes



arunvv
4th May 2007, 19:47
Hi,

I want to restore saved values for qcomboboxes upon
restarting the application.
Can you please help me in doing this,

I am able to write settings to a file using QSettings.
and storing the file as *.ini format.

But while reading the settings I am not able to read
it properly, using settings.value(...) function.

Can anybody had this problem, please help me out in
restoring the stored values for QComboBoxes upon restarting the application.

Or do I need to use any other alternative to restore application values upon restarting the application. Help me with some code.

Thanks & Regards,
Arun.

jpn
4th May 2007, 19:53
I want to restore saved values for qcomboboxes upon
restarting the application.
Would you mind showing the relevant code what you've got so far and we'll help filling in the gaps?

arunvv
4th May 2007, 20:04
Here is the Code :


void Settings :: readSettings()
{
QSettings settings("configWda.ini",QSettings::IniFormat);
settings.beginGroup("session");
restoreState(settings.value("Layout").toByteArray());
settings.setValue("WSMTxRate",wsmTxRate);
settings.endGroup();
}

void Settings :: writeSettings()
{
QSettings settings("configWda.ini",QSettings::IniFormat);
settings.beginGroup("session");
wsmTxRate = WSMTxRate->currentIndex();
settings.setValue("WSMTxRate",wsmTxRate);
printf("WSMTxRate is : %d \n", wsmTxRate);
//settings.setValue("WSMTxRate",WSMTxRate->currentIndex());
settings.remove("Layout");
settings.setValue("Layout",saveState());
settings.endGroup();
}

void Settings :: closeEvent(QCloseEvent *event)
{
writeSettings();
event->accept();
}

calling the readSettings function in constructor.

jpn
4th May 2007, 20:16
readSettings() indeed doesn't restore the current index of the combo box. I think you might be looking for something like this:

void Settings :: readSettings()
{
[...]
//settings.setValue("WSMTxRate",wsmTxRate); // <-- wrong
WSMTxRate->setCurrentIndex(settings.value("WSMTxRate").toInt()); // <-- try something like this
[...]
}

arunvv
4th May 2007, 21:17
Thanks it worked

Thanks for your imm. reply.

arunvv
4th May 2007, 22:40
Hi ,

I have few more doubts ,
1) After your recommended changes my application is working fine when I close.
2) If I kill or send some SIGTERM signal it is not restoring the values changed.
3) How to handle those changes to reflect even if the application is killed or send SIGTERM siganl.

Thanks & Regards,
Arun

wysota
4th May 2007, 22:43
Call QSettings::sync() after changing the settings (for example after calling setValue()).

arunvv
4th May 2007, 22:59
QSettings::sync() is not working.
I am calling writeSettings() inside closeEvent() function.
Is it to do any thing with this type calling , for not working QSettings::sync()
If this doesn't help ,is there any alternative to handle Kernal signals(like kill, SIGTERM).

Thanks & Regards,
Arun

wysota
5th May 2007, 08:37
If you kill an application closeEvent will not fire, hence writeSettings() will not be called. So you have to make sure the object is synced with the data storage after each call to setValue(). Alternatively register a handler for the SIGTERM signal and save the settings there. Of course this won't work for SIGKILL or SIGSEGV - the first can't be intercepted and the second may be signaled when your application is in an unpredictable state due to invalid memory access.

arunvv
7th May 2007, 18:29
Can you provide me the source code how to handle Signals with alternative method (not able to sync with QSettings)

Thanks & Regards
Arun

wysota
7th May 2007, 19:56
man signal