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
QtWS25 Last Chance

[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 17 Jul 2015, 12:02 last edited by mkolenda 8 Mar 2015, 20:52
    #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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Jul 2015, 22:26 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

      1/2

      17 Jul 2015, 12:02

      • Login

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