qtableview get selected row
To get the selected row in a QTableView in C++, you can use the QTableView's selection model. Here's an example:
QItemSelectionModel *selectionModel = tableView->selectionModel();
QModelIndexList selectedRows = selectionModel->selectedRows();
if (!selectedRows.empty()) {
int selectedRow = selectedRows.first().row();
// Do something with the selected row
}
This code snippet retrieves the selection model from the QTableView and then uses the selectedRows()
function to get a list of selected rows. If there is at least one selected row, it retrieves the index of the first selected row using row()
. You can then perform the desired operations with the selected row.
Remember to replace tableView
with the actual name of your QTableView object.