Results 1 to 3 of 3

Thread: How to make a clean exit when application is terminated by "kill" command

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a clean exit when application is terminated by "kill" command

    If you're talking about UNIX "kill" command, it send a SIGNAL to the application.
    Some signals can be handled bou others cannot. Read here and here for more details.

    If you handle a signal, you can send a quit event to QApplication
    A camel can go 14 days without drink,
    I can't!!!

  2. #2
    Join Date
    Jul 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make a clean exit when application is terminated by "kill" command

    Thanks,

    I finally make it work by this code:

    void signalhandler(int sig)
    {
    if (sig == SIGINT)
    {
    printf("will quit by SIGINT\n");
    qApp->quit();
    }
    else if (sig == SIGTERM)
    {
    printf("will quit by SIGTERM\n");
    qApp->quit();
    }
    }

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    autoprint w;
    signal(SIGINT,signalhandler);
    signal(SIGTERM,signalhandler);
    QObject::connect(&a, SIGNAL(aboutToQuit()),&w,SLOT(cleanup()));
    w.show();
    return a.exec();
    }

Similar Threads

  1. Replies: 7
    Last Post: 20th October 2012, 13:44
  2. Replies: 10
    Last Post: 9th September 2010, 16:43
  3. "make install" and "make clean" on Windows for Qt
    By Berberis in forum Installation and Deployment
    Replies: 0
    Last Post: 29th November 2009, 23:02
  4. Replies: 0
    Last Post: 15th November 2009, 09:40
  5. Replies: 3
    Last Post: 11th January 2009, 05:22

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.