4

I want to disable the close button on the window (main application window) when an operation starts so user can't exit the application and enable it again when the operation is complete. How can I do that in Qt application? My platform is windows 7.

Alternatively I could show a message if user press close button and exiting application that a process is running in the background and abort closing the application.

How can I do either?

zar
  • 11,361
  • 14
  • 96
  • 178
  • 2
    Here is something that may help you http://stackoverflow.com/questions/17480984/qt-how-do-i-handle-the-event-of-the-user-pressing-the-x-close-button – Robert Wadowski Jul 22 '15 at 18:20

1 Answers1

5

If you want disable button, you can use next:

auto flags = windowFlags();//save current configuration
//your main configuration which do the trick
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint );
//...
setWindowFlags(flags);//restore

If you are sure that such "feature" will not irritate your users, you can use this, in another case use link from the comment.

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • 3
    thanks but this causes the application to exit prematurely. `MyApp.exe exited with code 0` when this is called. – zar Jul 22 '15 at 19:34