title: QLayout and Valgrind
body: <p>I've been struggling with a message from Valgrind.
  I'm using a QLayout taken from Qt examples (FlowLayout) and I add at runtime, when the user presses an add button, some widgets to this layout.
  This is the initialitation snippet inside a constructor of my container QWidget class inherited:</p>
  
  <pre><code>// scroll area
  auto* central = new QWidget();
  central-&gt;setObjectName("CentralWidget");
  m_layout = new FlowLayout;
  ui-&gt;scrollArea_step-&gt;setFrameShape(QFrame::NoFrame);
  central-&gt;setLayout(m_layout);
  ui-&gt;scrollArea_step-&gt;setWidgetResizable(true);
  ui-&gt;scrollArea_step-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  ui-&gt;scrollArea_step-&gt;setWidget(central);
  </code></pre>
  
  <p>I've understood that because of the setWidget(central), I don't need to assign a parent to the "central" widget.</p>
  
  <p>When the user clicks the add button into the interface, the program invokes this snippet:</p>
  
  <pre><code>// create the button from rf data
  ShortMenuPushButton* stepButton = _createStepButton(m_rfData);
  m_layout-&gt;addWidget(stepButton);
  QPushButton* deleteStepButton = _createDeleteButton();
  m_layout-&gt;addWidget(deleteStepButton);
  </code></pre>
  
  <p>_createStepButton has this code:</p>
  
  <pre><code>auto* stepButton = new ShortMenuPushButton(this);
  </code></pre>
  
  <p>The same operation is done by _createDeleteButton() for the other button.</p>
  
  <p>If I run Valgrind, I get the same message:</p>
  
  <pre><code>==59123== 176 bytes in 2 blocks are definitely lost in loss record 8,040 of 8,630
  ==59123==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==59123==    by 0x6430849: QLayoutPrivate::createWidgetItem(QLayout const*, QWidget*) (qlayout.cpp:200)
  ==59123==    by 0x6431AA0: QLayout::addWidget(QWidget*) (qlayout.cpp:236)
  ==59123==    by 0x7DA967: Dialogs::Dialog_multistep::onButtonAddStep_clicked() (dialog_multistep.cpp:419)
  ==59123==    by 0x7E8B13: QtPrivate::FunctorCall&lt;QtPrivate::IndexesList&lt;&gt;, QtPrivate::List&lt;&gt;, void, void (Dialogs::Dialog_multistep::*)()&gt;::call(void (Dialogs::Dialog_multistep::*)(), Dialogs::Dialog_multistep*, void**) (qobjectdefs_impl.h:152)
  ==59123==    by 0x7E8A87: void QtPrivate::FunctionPointer&lt;void (Dialogs::Dialog_multistep::*)()&gt;::call&lt;QtPrivate::List&lt;&gt;, void&gt;(void (Dialogs::Dialog_multistep::*)(), Dialogs::Dialog_multistep*, void**) (qobjectdefs_impl.h:185)
  ==59123==    by 0x7E89B4: QtPrivate::QSlotObject&lt;void (Dialogs::Dialog_multistep::*)(), QtPrivate::List&lt;&gt;, void&gt;::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (qobjectdefs_impl.h:414)
  ==59123==    by 0x9284CB5: call (qobjectdefs_impl.h:394)
  ==59123==    by 0x9284CB5: QMetaObject::activate(QObject*, int, int, void**) (qobject.cpp:3774)
  ==59123==    by 0x64FAFF1: QAbstractButton::clicked(bool) (moc_qabstractbutton.cpp:312)
  ==59123==    by 0x64FB1F3: QAbstractButtonPrivate::emitClicked() (qabstractbutton.cpp:414)
  ==59123==    by 0x64FCD8D: QAbstractButtonPrivate::click() (qabstractbutton.cpp:407)
  ==59123==    by 0x64FCEE4: QAbstractButton::mouseReleaseEvent(QMouseEvent*) (qabstractbutton.cpp:1011)
  </code></pre>
  
  <p>But in FlowLayout I've the distructor with:</p>
  
  <pre><code>void FlowLayout::clear()
  {
      QLayoutItem* item;
      while ((item = takeAt(0)))
      {
          delete item-&gt;widget();
      }
  }
  </code></pre>
  
  <p>I do not understand where the leak is.</p>
  
  <p>I appreciate any suggestion.
  Thank you</p>