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] QComboBox setup by model, how to get other column?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QComboBox setup by model, how to get other column?

Scheduled Pinned Locked Moved General and Desktop
sqlqcombobox
2 Posts 2 Posters 1.8k 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 last edited by mkolenda
    #1

    I've made QComboBox with

    model->setQuery("SELECT id, name FROM myTable");
    ui->comboBox->setModel(model);
    ui->comboBox->setModelColumn(1);
    

    How to get real sql id from inside of below function because it seems to me that comboBox id's are strictly auto-incremented starting from 0 and have nothing in common with model.

    I cannot find id by name because names couldn't be unique. This is possible to add QVariant data using QComboBox::addItem(...) function. Maybe this is clue?

    void MainWindow::on_comboBox_currentIndexChanged(int index)
    {
    
    }
    
    1 Reply Last reply
    0
    • N Offline
      N Offline
      NetZwerg
      wrote on last edited by
      #2

      Try

      model->data(model->index(index,1));
      
      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