The condition looks good, it is more likely that you have an error elsewhere, especially if "the program crashes down" means it unexpectedly terminates.
Alternatively look at QTableWidget::selectedItems() to directly get the selected cells.
Cheers,
_
Bookmarks