@jdent said in How to add a row to a subclass of QAbstractTableModel?:
How do I find out which is the current row number in the QTableView?
Depending on what you want, any of the following:
QModelIndex QAbstractItemView::currentIndex() const
QModelIndexList QTableView::selectedIndexes() const
QItemSelectionModel *QAbstractItemView::selectionModel() const and call QModelIndex QItemSelectionModel::currentIndex() const
However, note that usually you do not need the currently selected row number. If you are asking about this in order to preserve/restore the current row after making a change: if you insert/delete/update a row I think you will find the table view maintains the currently selected row for you.
If you refill/invalidate the whole table and wish to retain/restore the previous current row you should (probably) not do that by row number as that may have changed due to to the new data. Rather you should look at the data in the current row before the refresh, keep some "primary key" which uniquely identifies the data in that row, refill the data, find the index in the new data of the saved "primary key" and call void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) to reselect wherever that item appears in the model's new data.