Results 1 to 4 of 4

Thread: aboutToQuit() signal from QCoreApplication

  1. #1
    Join Date
    Sep 2009
    Location
    Poland, Cracow
    Posts
    34
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default aboutToQuit() signal from QCoreApplication

    Is there any possibility if slot connected to aboutToQuit() signal is really called? The cout doesn't work (which is also described in docs). Is there anything I can do to make sure?

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

    Default Re: aboutToQuit() signal from QCoreApplication

    Quote Originally Posted by googie View Post
    Is there any possibility if slot connected to aboutToQuit() signal is really called?
    Why not?

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QtDebug>
    4.  
    5. class Button : public QPushButton {
    6. Q_OBJECT
    7. public slots:
    8. void doSomething() { qDebug() << "About to quit!"; }
    9. };
    10.  
    11. #include "main.moc"
    12.  
    13. int main(int argc, char **argv){
    14. QApplication app(argc, argv);
    15. Button button;
    16. button.setText("Click me");
    17. QObject::connect(&app, SIGNAL(aboutToQuit()), &button, SLOT(doSomething()));
    18. QObject::connect(&button, SIGNAL(clicked()), &app, SLOT(quit()));
    19. button.show();
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    user4592357 (6th December 2017)

  4. #3
    Join Date
    Sep 2009
    Location
    Poland, Cracow
    Posts
    34
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: aboutToQuit() signal from QCoreApplication

    Does it work for you when you close application from command line by pressing Ctrl+c ?

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

    Default Re: aboutToQuit() signal from QCoreApplication

    It will work if you install an appropriate signal handler. Otherwise the application is instantly terminated by the operating system and doesn't have a chance to do anything.

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QtDebug>
    4. #include <signal.h>
    5.  
    6.  
    7. class Button : public QPushButton {
    8. Q_OBJECT
    9. public slots:
    10. void doSomething() { qDebug() << "About to quit!"; }
    11. };
    12.  
    13. #include "main.moc"
    14.  
    15. void signalhandler(int sig){
    16. if(sig==SIGINT){
    17. qApp->quit();
    18. }
    19. }
    20.  
    21. int main(int argc, char **argv){
    22. QApplication app(argc, argv);
    23. Button button;
    24. button.setText("Click me");
    25. QObject::connect(&app, SIGNAL(aboutToQuit()), &button, SLOT(doSomething()));
    26. QObject::connect(&button, SIGNAL(clicked()), &app, SLOT(quit()));
    27. button.show();
    28. signal(SIGINT, signalhandler);
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  4. Replies: 2
    Last Post: 17th May 2006, 21:01

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
  •  
Qt is a trademark of The Qt Company.