I'm having some problems with removing tabs from QTabWidget. I have this QTabWidget with a main tab, named (surprise!) mainTab. At runtime the user can open several new tabs to view text documents. In order to close these tabs again I have provided a push button, cmdClear. The code for the button is:

Qt Code:
  1. void QtTextSearcher::on_cmdClear_clicked()
  2. {
  3. int count = ui.mainTab->count();
  4. int i = 1;
  5. for (i=1; i<count; ++i)
  6. {
  7. ui.mainTab->widget(i)->deleteLater();
  8. ui.mainTab->removeTab(i);
  9. }
  10. ui.txtOutput->clear();
  11. ui.txtLog->append("Cleared");
  12. }
To copy to clipboard, switch view to plain text mode 

When I press the buttton it doesn't delete all the document tabs however, it seems to always forget some. How come? I want it to delete all the tabs save the first mainTab.

Also: How can I position my QTabWidget like in the Assistant? In the Assistant the Tabwidgets are touching the toolbar, in designer I can't seem to get my Tabwidget anywhere near the edges of the mainwindow.