to remove rows from QTableWidget you have to
run the loop in reverse order. like this:
in python do this:
for x in reversed(range(self.tableWidget.rowCount())):
self.tableWidget.removeRow(x)
for c++ do this:
for (int i=view->rowCount()-1; i >= 0; --i)
removeRow(i);
for (int i=view->columnCount()-1; i>=0; --i)
removeColumn(i);