Also, you need to set number of rows and columns before populating tableWidget:
ui->tableWidget->setRowCount(numberOfRows)
and
ui->tableWidget->setColumnCount(numberOfColumnss)
Since you do not know how many rows you'll need (because you want the user to have the ability to edit lines from line to line infinity) I would do it like this:
ui->tableWidget->setRowCount(2);
...add only 2 rows ("line zero and one"), so user will have visible only two lines that he must fill. You'll need mechanism to check if all cells are filled (for example: every time cell item isChanged you check all other items if they are filled - not empty) so only when they are, user will be able to pass to editing new line, which you will add to table dynamically for every next row like this:
rowNumber = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowNumber);
for (int col=0; col< ui->tableWidget->columnCount(); col++){
item = new QTableWidgetItem;
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
ui->tableWidget->setItem(rowNumber ,col,item);
}
I hope this helps.