質問

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);
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top