Results 1 to 6 of 6

Thread: Restore the GUI to previous state when System signal occurs

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Restore the GUI to previous state when System signal occurs

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Restore the GUI to previous state when System signal occurs

    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?

  3. #3
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Restore the GUI to previous state when System signal occurs

    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",Configtabwidge t->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();
    }

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Restore the GUI to previous state when System signal occurs

    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?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Restore the GUI to previous state when System signal occurs

    Also, looks like you create a new MainWindow object in sighandler(). It's not the original window you have shown but another object..
    J-P Nurmi

  6. #6
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Restore the GUI to previous state when System signal occurs

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.