PDA

View Full Version : Closing Modeless Dialogs from MainWindow Application



jeffd589
12th February 2013, 00:01
I have a simple MainWindow application that contains one pushbutton. The pushbutton action starts a modeless dialog window (using "show"). When the MainWindow closes, the modeless dialog is still hanging out there. How do you close a modeless dialog from the MainWindow app? Should there be a signal/slot mechanism to perform the modeless dialog close?

d_stranz
12th February 2013, 00:36
Are you creating your modeless dialog with the MainWindow as its parent? If so, then the MainWindow destructor should close it automatically. If not (as seems to be the case), then you are telling Qt that this is a top-level window just like MainWindow, so closing MainWindow has no effect (as you observe).

If you don't want the dialog to be a child of MainWindow, then implement the closeEvent handler for your MainWindow class, and in it close your modeless dialog.