Hi

I think there's a small error in the mdi example shipped with qt:

the closeEvent in the main window is

void MainWindow::closeEvent(QCloseEvent *event)
{
     mdiArea->closeAllSubWindows();
     if (activeMdiChild()) {
         event->ignore();
     } else {
         writeSettings();
         event->accept();
     }
}

and activeMdiChild() is

MdiChild *MainWindow::activeMdiChild()
{
     if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
         return qobject_cast<MdiChild *>(activeSubWindow->widget());
     return 0;
}

thus it returns the active sub window.
However, on closing the application, if one of the subwindows cancels 
the close event the application closes anyway, since 
mdiArea->activeSubWindow() returns 0.

Instead of activeSubWindow(), the currentSubWindow() should be used. 
Thus, the closeEvent should read

void MainWindow::closeEvent(QCloseEvent *event)
{
     mdiArea->closeAllSubWindows();
     if (mdiArea->currentMdiChild()) {
         event->ignore();
     } else {
         writeSettings();
         event->accept();
     }
}

-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net

_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to