maybe you should check the values returned from tableWidget::item(), because the functions can return 0 if no item is asigned to the provided coordinates, and in that case you're trying to call a method (QTableWidgetItem::text()) on a zero pointer. Try something like:
QString R1;
QTableWidgetItem *item1(ui->tableWidget->item(row,0));
if (item1) {
R1 = item1->text();
}
// and so on...
Your code looks strange anyway, the 5th line (ui->tableWidget->rowCount()) doesn't make sense, you shouldn't be able to compile that (at least you're missing a semicolon).