PDA

View Full Version : Best Practice - delete pointer QAbstractButton in QMessageBox



estanisgeyer
12th March 2008, 13:38
Good day,
In this example below, delete the pointer is correct for the QAbstractButton or not I do that? What is the best practice?



QMessageBox msg(QMessageBox::Warning, tr("APP"),
QMessageBox::tr("blablablablablabla"), 0, this);

QAbstractButton *sim = msg.addButton(tr("&Sim"), QMessageBox::AcceptRole);
QAbstractButton *nao = msg.addButton(tr("&Não"), QMessageBox::RejectRole);
msg.exec();

delete sim;
delete nao;

if (msg.clickedButton() == sim)
{
......
}



Thanks,

Marcelo E. Geyer
Brazil

jpn
12th March 2008, 13:43
Those buttons are children of the messagebox and they'll get automatically destructed when the message box itself gets destructed. You don't have to delete them yourself at all. For more details, see: Object Trees and Object Ownership (http://doc.trolltech.com/4.3/objecttrees.html).