PDA

View Full Version : How do I distroy an object when clicking on the x?



RubyTigerSG
2nd April 2011, 11:45
Hi Gurus,

I have a gui which calls another gui like so:


if (userManager==0)
{
userManager = new UserManager();

}
userManager->show();



This then launches the user manager window. So now how do I make sure that the ~UserManager gets executed when someone closes the window by clicking on the x?

I know I should delete the reference to UserManager, but where do I do this?

Thanks a million
RT

Zlatomir
2nd April 2011, 12:02
You can use:

userManager->setAttribute(Qt::WA_DeleteOnClose, true);
It will be deleted by QObject::deleteLater() (http://doc.qt.nokia.com/latest/qobject.html#deleteLater)

ChiliPalmer
3rd April 2011, 13:48
Additionally, to make sure your Pointer is set to null after the window is closed, you could either use http://doc.trolltech.com/4.7/qobject.html#destroyed or a QPointer