Results 1 to 4 of 4

Thread: cleanup handler on application close

  1. #1
    Join Date
    Aug 2006
    Location
    Darmstadt
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question cleanup handler on application close

    hi, i have a small application which builds up a connection to a digital camera. To take a photo you have to set up "releaseMode". After the desired camera operations you have to part this releaseMode to finish clean. Otherwise you couldn't enter the releaseMode again.

    so i need to do some cleanup operations. How to realize this? I thought about handling the QCoreApplication::aboutToQuit() signal, but it doesn't work yet.

    Here my little test application

    the receiver-class

    Qt Code:
    1. class Nonce : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Nonce();
    7. ~Nonce();
    8.  
    9. public slots:
    10. void quitter();
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 


    quitter method

    Qt Code:
    1. void Nonce::quitter()
    2. {
    3. std::cout << " aboutToQuit emitted "<< std::endl << std::flush;
    4. }
    To copy to clipboard, switch view to plain text mode 


    and a small main()

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4.  
    5. Nonce foo;
    6.  
    7. QObject::connect(&a, SIGNAL(aboutToQuit()),
    8. &foo, SLOT(quitter()));
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 


    so.. when i "kill" the programm anyway the quitter method should be started, there i want leave the releaseMode.

    any Ideas where are my faults? (yeah, I am quite new to Qt)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: cleanup handler on application close

    Quote Originally Posted by err23
    when i "kill" the programm anyway the quitter method should be started
    When you kill your application, it is terminated immediately.

  3. #3
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: cleanup handler on application close

    Jacek, actually how to properly end a QCoreApplication to trigger aboutToQuit() signal, without pressing the 'X' button in right-top corner, or type Ctrl+C in keyboard? Both of these 2 actions will still KILL the QCoreApplication immediately.

    Quote Originally Posted by jacek
    When you kill your application, it is terminated immediately.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: cleanup handler on application close

    Quote Originally Posted by ball
    Jacek, actually how to properly end a QCoreApplication to trigger aboutToQuit() signal, without pressing the 'X' button in right-top corner, or type Ctrl+C in keyboard? Both of these 2 actions will still KILL the QCoreApplication immediately.
    There are many ways. If it has a some form of CLI, then you have to implement proper command or if it works more like a daemon, you can use some IPC mechanism (like signals).

    AFAIR Ctrl+C should send SIGINT and that 'X' button -- SIGTERM, so you can use your own handler that will send a custom event to your application object to make it invoke quit(). Of course this means that your console application must be event-driven.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51
  2. How to close application?
    By beerkg in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2006, 19:26

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.