[SOLVED] QListView key-value pair from SQL table

  • I have SQL table(id, name). I want to load names into QListView and on selection show QMessageBox with id related to selected name.

    I've tried QSqlQueryModel with QSqlQuery such as "SELECT name, id from table" and this is making listView looking as I expect but how can I fetch related id from the model while being inside of on_listView_clicked(const QModelIndex &index) ?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    They index provides you the row/column of the clicked item, so you can request the data from the index of the id column and the same row that you just clicked.

    Hope it helps