I am having trouble getting the index value from a QComboBox that uses a model loaded with Data from a table in a database.
I can get the value out in the same function that loads the QComboBox but not from a button clicked function.
I am sure there is something simple, but it eludes me.
Here is the code that works
QString qlstr = "SELECT * from CellList ORDER BY designator ASC";
QSqlQuery modelquery;
modelquery.exec(qlstr);
QSqlQueryModel *modelCell = new QSqlQueryModel(this);
modelCell->setQuery(modelquery);
modelCell->setHeaderData(0, Qt::Horizontal, "UserID");
ui->cmbCellList->setModel(modelCell);
ui->cmbCellList->setModelColumn(1);
QSqlRecord record = modelCell->record(ui->cmbCellList->currentIndex());
QString lstr;
lstr = record.value(0).toString();
ui->lineEdit->setText(lstr);
but in the button click function when i try to fill the lineEdit with
QSqlRecord record = modelCell->record(ui->cmbCellList->currentIndex());
QString lstr;
lstr = record.value(0).toString();
ui->lineEdit->setText(lstr);
program breaks. It seems as if the modelCell is no longer available.
Any help would be most appreciated.
Bookmarks