PDA

View Full Version : Memory returned for child widgets after closing



koan
26th April 2011, 11:02
QT handles memory deletion for child objects; I want to open a progress dialog and give a parent widget so I can set the Qt::Sheet window property.

If I open a progress dialog; i.e. QProgressDialog *mydialog = new QProgressDialog("Busy...", "Stop", start, stop, parent), then can I assume that QT will recycle/free memory if I mydialog->close() and then open a new one later ?

I'm concerned that if my function gets called many times I could do something nasty if QT doesn't take care of the memory. Is it the proper way, to just leave it for QT ?

Zlatomir
26th April 2011, 12:01
As far as i know this should be fine, the attribute Qt::WA_DeleteOnClose is false by default, so you should be able to allocate memory (construct a widget) once and show-close... multiple times without the pointer to become invalid.

//i didn't test this, i just deduced it should work, so you can make a small project and test with a debugger, or wait an answer for someone that can confirm with experience what i said (or maybe correct what i said - if i'm wrong).

AlexSudnik
26th April 2011, 15:36
Since you've got a QObject instance parented , as long as a parent exists,it's children will exist as well ( unless you delete them manually ).In your case, you can always check it with a QObjectList QObject::children() const method : as new dialogs appear,objectList.count() will get bigger as well.

So you can delete newly created objects manually or use more a little more convinient QScopedPointer class.