PDA

View Full Version : How to block a software or widget from being closed



Momergil
27th April 2013, 06:07
Hello!

I'm having a problem regarding closing a software while a thread is running.

The problem is that the thread is declared locally and it takes something like 5-8 seconds to do its job. So I'ld like to block the application from closing while the thread is running and when it finishes, the blockage should end. But how could I do that in a normal QMainWindow? I could easily setDisabled(true) in the exit actions, but that wouldn't block the X button in the widget.

Another, even better situation would be to not block the exit buttons, but if they are pressed while the thread is running, than a QMessageBox appears saying that it's not possible to close the software yet and than the signal for closing is "canceled".

Notice: no problem if the user force the software to quit by the task manager.


Thanks,

Momergil

wysota
27th April 2013, 07:12
Reimplement closeEvent for your window and ignore() the event to prevent the window from closing.

Momergil
27th April 2013, 15:54
It worked fine, but in the solution with the message presentation. But what if I wanted to block the closing of the app by blocking the X button in the window?

wysota
27th April 2013, 16:25
The solution I provided works for every window.