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
and here is the .h file
the constructor uses the new operator but the class doesn’t have a destructor. Am I missing something?
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.
Answered By – erelender
Answer Checked By – Gilberto Lyons (BugsFixing Admin)