views:

262

answers:

1

Im new to the Qt library and i was going through the demonstrations. I came across this class without a destructor....

this is the cpp file http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-cpp.html

and here is the .h file http://doc.trolltech.com/4.5/demos-mainwindow-mainwindow-h.html

the constructor uses the new operator but the class doesn't have a destructor. Am I missing something?

+9  A: 

Yes you are. Qt provides parent-child relationship. When a QObject is deleted, it deletes all of its children automatically.

In the line below, a QTextEdit is created with this pointer as its parent.

center = new QTextEdit(this);

So, when the parent (MainWindow) is deleted, center is automatically deleted too. Take a look at the QObject documentation.

erelender
Also I noticed if I don't alloc center with `operator new()` but I put it as a class instance of an object I don't get double-free-corruption. How is it possible? — Got my answer: http://doc.trolltech.com/4.5/qpointer.html
Dacav