PDA

View Full Version : Some quest about the closeEvent in QMainWindow



cspp
25th June 2009, 09:29
Hi all
I have an application with muti MainWindow. and thie close way:
The one way:


void MWindow::fileExit()
{
close(TRUE);
}


The another way:


void MWindow::closeEvent(QCloseEvent* ce)
{
penv->m_WindowList->GoHead(); //the list of all QMainWindow
do
{
if( pevn->m_WindowList->Object() == penv->currentWindow ) //
{
QMainWindow::closeEvent(ce);
break;
}
}
while(pevn->m_WindowList->GoNext())
}


The Destroy funtion


void MWindow::destroy()
{
//release the memory
}

My question is:
if I call the fileExit,it will call the destroy!
and if I click the close button on the QMainWindow,it will call the closeEvent,but not
call the destroy(),so my memery and GDI will leak!

and I want to how,if I want to support the close button, how I can do to avoid the memory and GDI leak.

Thanks.

PS:my platform is WinXp,Qt336,MSVC6.0.

wysota
25th June 2009, 09:50
Why should destroy() be called if you never call it yourself? Closing a window doesn't cause it to be deleted, it would be hard to retrieve any data from it then :) If you want such behaviour, then pass the DestructiveClose flag to each of the windows.

cspp
25th June 2009, 10:00
you means if i want to call the destroy when click the close button on the QMainWindow, I neet set the WFlags Qt::WDestructiveClose?
Isee,I use the QMainWindow in default, and I will try it later,
Thanks