Qt-interest Archive, May 2008
Endless loop in closeAllWindows
Message 1 in thread
Using Qt 4.3.4 I experience that Qt never leaves the function
closeAllWindows().
What I do is the following
void MainWindow::closeEvent ( QCloseEvent * event )
{
if (!m_OnQuitApplication)
quitProgram();
}
void MainWindow::quitProgram()
{
m_OnQuitApplication = true;
qApp->closeAllWindows();
qApp->quit();
}
closeEvent was implemented because it is required that quitProgram is
excecuted if the MainWindow is closed using the X Button.
However in this case closeAllWindows is never left, because the programm
gets stuck within the for loop of that function, which looks like this:
void QApplication::closeAllWindows()
{
...
QWidgetList list = QApplication::topLevelWidgets();
for (int i = 0; did_close && i < list.size(); ++i) {
w = list.at(i);
if (w->isVisible() && w->windowType() != Qt::Desktop) {
did_close = w->close();
list = QApplication::topLevelWidgets();
i = -1;
}
}
}
The if loop is always entered and thus the for-loop always restarts at 0.
How do I solve this problem ?
Matthias
--
[ signature omitted ]
Message 2 in thread
On Friday 02 May 2008 10:14:35 Matthias Pospiech wrote:
> How do I solve this problem ?
1) sanitize your stack layout. subwindows should be cleared in the mainwindow
dtor. so that problem shouldnt exist (unless you have multiple mainwindow in
which case your GUI layout is broken)
2)just qApp->quit();
the dtor of the windows will take care of shutting them down properly.
that assumes that you contsruct all windows on stack (which you should anyway)
3) QWidgetList QApplication::topLevelWidgets ()
and close all except the caller.
4) just don't care
sane window systems will clean up windows themselfs when the app quits anyway.
Unclean shutdown on windows, and X11 at least showed no leftovers at least for
me.
--
[ signature omitted ]
Message 3 in thread
Arvid Ephraim Picciani schrieb:
> On Friday 02 May 2008 10:14:35 Matthias Pospiech wrote:
>
>> How do I solve this problem ?
>>
>
> 1) sanitize your stack layout. subwindows should be cleared in the mainwindow
> dtor. so that problem shouldnt exist (unless you have multiple mainwindow in
> which case your GUI layout is broken)
>
>
All Dialogs (is that what you mean by subwindow) are declared within
mainwindow, except one dialog that needs to be accessed by every Dialog,
which is declared in a seperate file as 'extern'.
> 2)just qApp->quit();
> the dtor of the windows will take care of shutting them down properly.
> that assumes that you contsruct all windows on stack (which you should anyway)
>
That seems to work.
However my Dialogs are all declared on the heap, as this one:
QPointer<DialogBeamView> dlgBeamView;
I have never seen any Qt Example where Dialogs are not declared with a
pointer.
> 4) just don't care
> sane window systems will clean up windows themselfs when the app quits anyway.
> Unclean shutdown on windows, and X11 at least showed no leftovers at least for
> me.
>
I am using win XP, and here the dialogs simply freese, since the
function is never left.
Matthias
--
[ signature omitted ]