IMHO remove this and just replace with:
``ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));``

So no need for that loop below :).