Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QListView key-value pair from SQL table

[SOLVED] QListView key-value pair from SQL table

Scheduled Pinned Locked Moved General and Desktop
qtsqlqlistviewqsqlquerymodel
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mkolenda
    wrote on last edited by mkolenda
    #1

    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) ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved