Qt Application Cancellation Event

I was wondering if it is possible to ignore / cancel the exit from the application based on a specific logical flag, even if the user must press the red "X" button (close the window).

I am a C # programmer, and I know that it is quite easy to do for .net applications, but I am pretty new to the qt framework, and google search did not bring any relevant results.

Thanks,

+6
source share
1 answer

The Qt documentation describes this particular use case for a close request in its examples .

If you subclass QMainWindow , for example, and override the closeEvent function, you can provide your application with individual behavior when someone tries to close it. For instance:

 void MainWindow::closeEvent(QCloseEvent *event) { if (maybeSave()) { writeSettings(); event->accept(); } else { event->ignore(); } } 
+14
source

Source: https://habr.com/ru/post/904111/


All Articles