QApplication::quit() does not trigger closeEvent() of the main window?
-
Hi, all:
I have the same problem as the following:
https://forum.qt.io/topic/93678/qapplication-quit-does-not-trigger-closeevent-of-the-main-window-by-design-or-bugIs there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.
-
Hi, all:
I have the same problem as the following:
https://forum.qt.io/topic/93678/qapplication-quit-does-not-trigger-closeevent-of-the-main-window-by-design-or-bugIs there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.
@LiaoXuewei said in QApplication::quit() does not trigger closeEvent() of the main window?:
Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.
It is not a bug. Reimplement closeEvent() and it will be triggered when the user attempts to close the application.
It will not be triggered when your code attempts to quit the app. So, a solution is to use QWidget::close() instead of QApplication::quit() in your case.
-
@LiaoXuewei said in QApplication::quit() does not trigger closeEvent() of the main window?:
Is there any solution for it. I want to prevent application quiting by some condition, example ask user if application can quit, user choice [no]. It is a common requirements.
It is not a bug. Reimplement closeEvent() and it will be triggered when the user attempts to close the application.
It will not be triggered when your code attempts to quit the app. So, a solution is to use QWidget::close() instead of QApplication::quit() in your case.
@sierdzio Example, user close qt app by taskbar, but app cann't detect. Do you think it's normal?
-
Hi, all:
I am sorry, i had made a mistake.
I had test QApplication::quit() will trigger closeEvent() of the main window!
I had wrote closeEvent in sub window before, so did not trigger! -
OK, happy to see that it's solved :-)