PDA

View Full Version : delete QtObject



Lodhart
21st December 2009, 21:20
hi, last time i ask you about create several QPushButtons and connect these buttons with slots. Today want ask you to delete these buttons.

I create buttons and store their pointer to struct like: createdB[i] = new QPushButton;
When i destroy button i call: delete createdB[i]; it is OK, but ..

when a create for example a QMenu for QPushButton: QPushButton->setMenu(new QMenu); or insert same widget: QPushButton->layout->addWidget(..);

is it corect when i call only: delete createdB[i]; or i MUST call "delete" for everything what is create for button: delete QPushButton->layout...; delete QPushButton->menu..; and finally: delete createdB[i];

i'am not sure about this. thanks.

Lykurg
21st December 2009, 22:27
If your button is parent to all the stuff inside (I just wonder why your button has a layout you access...) then it is absolutely right only to delete the button. Qt will delete all children itself.
You might want use QObject::deleteLater().

Lodhart
22nd December 2009, 08:15
The layout button is for graphics..
And thanks a lot.;)