title: Qt: What is the correct and safe way to write the destructor of this class?
body: <p>I am using Qt5 on Windows7 and I recently found <a href="http://doc.qt.io/qt-5/qsignalmapper.html" rel="noreferrer">an interesting Qt example code</a>.  </p>
  
  <p>Basically, it looks like this:   </p>
  
  <pre><code>ButtonWidget::ButtonWidget(const QStringList &amp;texts, QWidget * parent) 
  : QWidget(parent)
  {
      signalMapper = new QSignalMapper(this);
  
      QGridLayout * gridLayout = new QGridLayout;
      for (int i = 0; i &lt; texts.size(); ++i) 
      {
          QPushButton * button = new QPushButton(texts[i]);
          connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
          signalMapper-&gt;setMapping(button, texts[i]);
          gridLayout-&gt;addWidget(button, i / 3, i % 3);
      }
  
      connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(clicked(QString)));
  
      setLayout(gridLayout);
  }
  </code></pre>
  
  <p>It is a nice and useful example, but it doesn't have a proper destructor... just in case I want to delete an object of <code>ButtonWidget</code> type, or if I want to customise the code to be able to remove/add widgets.    The idea is how to delete all objects created in the constructor (dynamically, using <code>new</code>).</p>
  
  <p>My approach was to use a private variable <code>QList&lt;QPushButton*&gt; list</code>, add all new-allocated buttons to list (in the constructor) and delete them one-by-one in the destructor, using the above <code>list</code>. But it seems so kindergarten-approach.   </p>
  
  <p>I think there must be some other way, better way to do it, without a list and without messing the constructor code :) Thanks for your time and patience!</p>