Answer the question
In order to leave comments, you need to log in
QComboBox and DB, how to get ID?
I get the ID like this:
....
Region= new QComboBox;
qry.exec("SELECT * FROM region");
model->setQuery(qry);
Region->setModel(model);
Region->setModelColumn(3);
connect(Region, SIGNAL(currentTextChanged(QString)), SLOT(comboChange(QString)));
void MyWidget::comboChange(QString str)
{
QSqlQuery qry1;
qry1.prepare("SELECT region_id FROM region WHERE name=?");
qry1.addBindValue(str);
qry1.exec();
int reg;
while(qry1.next())
reg = qry1.value(0).toInt();
//qDebug() << reg;
emit toRegion(reg);
}
.......
Answer the question
In order to leave comments, you need to log in
Use QComboBox::setItemData() when filling the combobox: you can add data invisible to the user to the items. In comboChange QComboBox::itemData() will allow them to be received.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question