Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. should QPushButton added to a QMessageBox be freed from memory?

should QPushButton added to a QMessageBox be freed from memory?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 219 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    walle19
    wrote on last edited by
    #1

    Hi,

    I have the following code:

            QMessageBox* box= new QMessageBox();
    	box->setAttribute(Qt::WA_DeleteOnClose, true);
    	box->setWindowTitle(tr("msg_box"));
    	box->setText(tr("random text"));
    	QAbstractButton* btn_a= box->addButton(tr("btn_a"), QMessageBox::YesRole);
            QAbstractButton* btn_b= box->addButton(tr("btn_b"), QMessageBox::YesRole);
            QAbstractButton* btn_close = box->addButton(tr("Close"), QMessageBox::NoRole);
    

    It is not specified in the documentation if the memory allocated for the added buttons should be freed by the user that called addButton. Or maybe they are freed after the QMessageBox is deleted because adding them to the QMessageBox define them as children of the QMessageBox?

    Or should I explicitly free them from memory once finished with the QMessageBox?

    Thanks for your time.

    VRoninV 1 Reply Last reply
    0
    • W walle19

      Hi,

      I have the following code:

              QMessageBox* box= new QMessageBox();
      	box->setAttribute(Qt::WA_DeleteOnClose, true);
      	box->setWindowTitle(tr("msg_box"));
      	box->setText(tr("random text"));
      	QAbstractButton* btn_a= box->addButton(tr("btn_a"), QMessageBox::YesRole);
              QAbstractButton* btn_b= box->addButton(tr("btn_b"), QMessageBox::YesRole);
              QAbstractButton* btn_close = box->addButton(tr("Close"), QMessageBox::NoRole);
      

      It is not specified in the documentation if the memory allocated for the added buttons should be freed by the user that called addButton. Or maybe they are freed after the QMessageBox is deleted because adding them to the QMessageBox define them as children of the QMessageBox?

      Or should I explicitly free them from memory once finished with the QMessageBox?

      Thanks for your time.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @walle19 said in should QPushButton added to a QMessageBox be freed from memory?:

      Or maybe they are freed after the QMessageBox is deleted because adding them to the QMessageBox define them as children of the QMessageBox?

      Bingo! if they are sub-widgets then they are child and will be deleted with the parent

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved