PDA

View Full Version : Restore the GUI to previous state when System signal occurs



arunvv
8th May 2007, 00:55
To restore the values to previous state I am using QSettings to store the values in a file in *.ini format.
This is happening when closeEvent() function is called.
But I am trying to restore the values of GUI to previous state when application exits on system signal like SIGTERM or KILL.
Able to catch Unix signal like SIGTERM in Qtopia 4.2 using signal handler, but could not able to update the values of GUI using QSettings, when SIGTERM is signalled to application.

Thanks & Regards,
Arun

wysota
8th May 2007, 01:12
Please show the code. BTW. You won't be able to intercept SIGKILL. I think I already said that in another thread. Isn't this a double thread anyway?

arunvv
8th May 2007, 02:08
Hi Here is the code,

static void WriteSettings(int sigNum);

void sighandler(int sig)
{
MainWindow h;
h.writeSettings(); // On calling this Function it has to writeSettings. But not updating settings or indexes
sig = 0;
printf("This is when signal emits \n"); // This is printing when SIGTERM is caught
return ;
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFont f;
MainWindow h;
signal(SIGTERM, sighandler); // catching the Signal
h.resize(1024,768);
h.setWindowTitle("DENSO WAVE Demonstration Application V1.0.1");
f.setPixelSize(32);
QApplication::setFont(f);
h.show();
return app.exec();
}

void MainWindow::writeSettings()
{
QSettings settings("configWda.ini",QSettings::IniFormat);
settings.beginGroup("session");
settings.sync();
settings.setValue("WSMTxRate",WSMTxRate->currentIndex());
settings.sync();
settings.setValue("TxPriority",TxPriority->currentIndex());
settings.sync();
settings.setValue("DataRate",DataRate->currentIndex());
settings.sync();
settings.setValue("TxPower",TxPower->currentIndex());
settings.sync();
settings.setValue("ConfigTabWidget",Configtabwidget->currentIndex());
settings.sync();
settings.setValue("IPTxRate",IPTxRate->currentIndex());
settings.sync();
settings.setValue("PSIDIndex",ProviderServiceID->currentIndex());
settings.sync();
settings.setValue("SPIndex",ServicePriority->currentIndex());
settings.sync();
settings.endGroup();
}

wysota
8th May 2007, 11:12
You don't need to sync() in this situation, because the object gets synced when it's deleted. Does the signal handler actually get called?

jpn
8th May 2007, 11:19
Also, looks like you create a new MainWindow object in sighandler(). It's not the original window you have shown but another object..

arunvv
9th May 2007, 21:31
It worked now, it was just the way I was calling the writeSettings function.

Here is the way I handled the signal for MainWindow.
signal(SIGTERM, MainWindow::writeSettings);

And declared static void writeSettings(int sigNum); in header file under public.
And thus this function has been called when SIGTERM signal is caught.

Thanks to all who supported me in correcting me from doing faults.