[SOLVED] How to store sql's ID and access it on QListView on click event to get this id?
General and Desktop
2
Posts
2
Posters
1.2k
Views
1
Watching
-
wrote on 29 Jul 2015, 18:54 last edited by mkolenda
I have
QSqlQueryModel model("SELECT name, id from x")
and i've set it onlistView->setModel(model)
How can I fetch id from this model fromvoid MainWindow::on_listView_doubleClicked(const QModelIndex &index) { }
-
wrote on 29 Jul 2015, 19:07 last edited by Resurr3ction
I would do:
int id = model->index(index.row(), 1).data().toInt();
The sequence of the columns in the query is the same as in the model and the view so 0=name, 1=id. The model is obtained either directly from the class where you have it or from the view using QListView::model().
1/2