Results 1 to 2 of 2

Thread: Best Practice - delete pointer QAbstractButton in QMessageBox

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Best Practice - delete pointer QAbstractButton in QMessageBox

    Good day,
    In this example below, delete the pointer is correct for the QAbstractButton or not I do that? What is the best practice?

    Qt Code:
    1. QMessageBox msg(QMessageBox::Warning, tr("APP"),
    2. QMessageBox::tr("blablablablablabla"), 0, this);
    3.  
    4. QAbstractButton *sim = msg.addButton(tr("&Sim"), QMessageBox::AcceptRole);
    5. QAbstractButton *nao = msg.addButton(tr("&Não"), QMessageBox::RejectRole);
    6. msg.exec();
    7.  
    8. delete sim;
    9. delete nao;
    10.  
    11. if (msg.clickedButton() == sim)
    12. {
    13. ......
    14. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer
    Brazil

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Best Practice - delete pointer QAbstractButton in QMessageBox

    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.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    estanisgeyer (12th March 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.