PDA

View Full Version : windows still exists after closeAllSubWindows()



ravas
27th October 2015, 09:50
Any idea why a window is found by mdiArea->currentSubWindow()
directly after mdiArea->closeAllSubWindows()?
mdiArea is a class member for a QMainWindow subclass.

The windows appear to have been closed after the function (QMainWindow::closeEvent) returns.
And the next time the function runs it will find the currentSubWindow to be null.



mdiArea->closeAllSubWindows();
qDebug() << mdiArea->subWindowList().length();


If I have 2 sub-windows open,
the debug ouput is 2.

Qt 5.5 / win 7

anda_skoa
27th October 2015, 12:59
My guess: there is no chance for the event loop to run between those two calls and the first call only calls close() on the subwindows.
Boy, wouldn't it be nice we could look at the code (http://code.woboq.org/qt5/qtbase/src/widgets/widgets/qmdiarea.cpp.html#_ZN8QMdiArea18closeAllSubWindows Ev) of that function?

Cheers,
_

ravas
27th October 2015, 20:13
mdiArea->closeAllSubWindows();
if (mdiArea->currentSubWindow()) {
ce->ignore();
} else {
ce->accept();
}


It worked before (close all subwindows then accept the close event),
but I recently subclassed QMdiSubWindow,
where before they were created automatically by mdiArea->addSubWindow(widget).
The only difference I can think of is that the subclass sets setAttribute(Qt::WA_DeleteOnClose);
however, removing that makes it so the subwindows aren't even closed.

Added after 21 minutes:

Another difference is that the QMdiSubWindow has a reimplemented closeEvent function;
although, that seems to run OK.

ravas
27th October 2015, 22:02
I'm thinking that calling closeAllSubWindows is not needed.
The windows will be dealt with when the main window is deleted.

Thanks for the idea about the event loop.