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] How to store sql's ID and access it on QListView on click event to get this id?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to store sql's ID and access it on QListView on click event to get this id?

Scheduled Pinned Locked Moved General and Desktop
qlistviewqsqlquerymodel
2 Posts 2 Posters 1.2k Views 1 Watching
  • 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 29 Jul 2015, 18:54 last edited by mkolenda
    #1

    I have QSqlQueryModel model("SELECT name, id from x") and i've set it on listView->setModel(model)
    How can I fetch id from this model from

    void MainWindow::on_listView_doubleClicked(const QModelIndex &index)
    {
    
    }
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      Resurr3ction
      wrote on 29 Jul 2015, 19:07 last edited by Resurr3ction
      #2

      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 Reply Last reply
      1

      1/2

      29 Jul 2015, 18:54

      • 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