title: Remove QLabel dynamically
body: <p>I am working to create a GUI with Qt and C++.</p>
  
  <p>I have create dynamically some couples of buddies (<code>QLabel</code> + <code>QSpinBox</code>) in order to refresh the number of errors that my program makes in the last thousand round to my loop.</p>
  
  <p>My code to create this:</p>
  
  <pre><code>if((num_fotos % 1000) == 0){
      if(num_layouts &lt; NUM_FAIL_COUNT){
          for(int i = 0; i &lt; (buffer-&gt;length()-1); i++){
              sum_100_fallos += int(buffer-&gt;at(i));
          }
          QLabel * label_1000 = new QLabel();
          label_1000-&gt;setText("Fallos 1000_" + QString::number(num_fotos/1000) + ": ");
          label_1000-&gt;setMinimumHeight(24);
          QSpinBox * spinBox_1000 = new QSpinBox();
          //newElements-&gt;append(label_1000);
          spinBox_1000-&gt;setReadOnly(true);
          spinBox_1000-&gt;setRange(0, 1000);
          spinBox_1000-&gt;setMinimumHeight(24);
          new_layouts[num_layouts] = new QHBoxLayout;
          //newElements-&gt;append(spinBox_1000);
          new_layouts[num_layouts]-&gt;addWidget(label_1000);
          new_layouts[num_layouts]-&gt;addWidget(spinBox_1000);
          spinBox_1000-&gt;setValue(num_fallos_1000);
          num_fallos_1000 = 0;
  
          ui-&gt;verticalLayout_5-&gt;addLayout(new_layouts[num_layouts]);
          num_layouts++;
      }else{
          aux = num_layouts % NUM_FAIL_COUNT;
          delete new_layouts[aux];
          for(int i = 0; i &lt; (buffer-&gt;length()-1); i++){
              sum_100_fallos += int(buffer-&gt;at(i));
          }
          QLabel * label_1000 = new QLabel();
          label_1000-&gt;setText("Fallos 1000_" + QString::number(num_fotos/1000) + ": ");
          label_1000-&gt;setMinimumHeight(24);
          QSpinBox * spinBox_1000 = new QSpinBox();
          //newElements-&gt;append(label_1000);
          spinBox_1000-&gt;setReadOnly(true);
          spinBox_1000-&gt;setRange(0, 1000);
          spinBox_1000-&gt;setMinimumHeight(24);
          new_layouts[aux] = new QHBoxLayout;
          //newElements-&gt;append(spinBox_1000);
          new_layouts[aux]-&gt;addWidget(label_1000);
          new_layouts[aux]-&gt;addWidget(spinBox_1000);
          spinBox_1000-&gt;setValue(num_fallos_1000);
          num_fallos_1000 = 0;
  
          ui-&gt;verticalLayout_5-&gt;addLayout(new_layouts[aux]);
          num_layouts++;
      }   
  }
  </code></pre>
  
  <p><code>NUM_FAIL_COUNT</code> is the numbers of (<code>QLabels</code> + <code>QLineEdit</code>) to show simultaneously.
  If there is less than <code>NUM_FAIL_COUNT</code>, I create new layouts and add them to the view. </p>
  
  <p><a href="https://i.stack.imgur.com/3YQRn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3YQRn.jpg" alt="View with NUM_FAIL_COUNT equals five"></a></p>
  
  <p>As you can see, this is what I am creating dynamically.
  But, if there are more than <code>NUM_FAIL_COUNT</code>, I want to remove the entire first layout, with its children in order to add the new one at the bottom. 
  What happens is that the first layout is removed, but not its children, overlapping the <code>QLabel</code> + <code>QLineEdit</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/veTR0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/veTR0.jpg" alt="Overlapping in first couple of buddies"></a></p>
  
  <p>I have tried accessing to it by <code>children()</code> call, with pointers, <code>deleteLater()</code>, and trying to clearing layout previously to its deletion.</p>
  
  <p>What am I thinking wrong?
  Thanks for your answer.</p>