Hello all,
I have a 2 tables. One of them have the following data:
ID Text
----------------
1 Apple
4 Banana
6 Mango
8 Rambutan
19 Durian
ID Text
----------------
1 Apple
4 Banana
6 Mango
8 Rambutan
19 Durian
To copy to clipboard, switch view to plain text mode
I got a QComboBox to populate with the right text using QSqlRelationalTableModel and QSqlTableModel:
// etc etc... populate database, set relations as per example on help files etc...
ui->myComboBox->setModel(relModel);
ui->myComboBox->setModelColumn(relModel->fieldIndex("Text"));
QSqlRelationalTableModel *rtmodel = new QSqlRelationalTableModel();
// etc etc... populate database, set relations as per example on help files etc...
QSqlTableModel * relModel = rtmodel->relationModel(typeIndex);
ui->myComboBox->setModel(relModel);
ui->myComboBox->setModelColumn(relModel->fieldIndex("Text"));
To copy to clipboard, switch view to plain text mode
The QComboBox shows the text fine, meaning I can choose the fruit I want. How do I get the selected text's ID once I've selected the text? Say, I picked Durian, how do I get myComboBox to return the value '19'?
Thanks.
Bookmarks