setSortRole() is a method of QStandardItemModel, not of any of the table view classes.
ALso, since QTableWidget is derived from QTableView, QTableWidget IS a QTableView, and you wouldn't need to switch between classes.