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



  • 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)
    {
    
    }
    


  • Try

    model->data(model->index(index,1));

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.