read QTableview selected row QSQLITE database
Frage
I show the data of a table (table1) in a QTableView. When the user selects a row, I want to read the data from this highlighted line. How can I do it easily?
For example will this read the whole data?
query.exec("SELECT * table1);
Lösung
I am assuming you are using a QSqlTableModel
with your view. In this case you can use currentIndex
in order to get the model index of the current item and then use the record
function of the QSqlTableModel
in order to get the record corresponding to the index's row:
QModelIndex curIndex = tableView->currentIndex();
QSqlRecord record = model->record(curIndex.row());
Then you can use the field
function of QSqlRecord
in order to get the values at the columns you want.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow