PDA

View Full Version : QSqlRelationalDelegate (ComboBox) id on first show



janus
5th September 2008, 11:21
Hi,

I have a relationalTableModel with one relation


cxcModel = new QSqlRelationalTableModel;
cxcModel->setTable("crop_x_cultivar");
cxcModel->setHeaderData(1, Qt::Horizontal, tr("Frucht"));
cxcModel->setHeaderData(2, Qt::Horizontal, tr("Sorte"));
cxcModel->setRelation(1, QSqlRelation("crop", "crop_id", "crop_name"));
cxcModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
cxcModel->select();
ui.tableViewCxC->setModel(cxcModel);
ui.tableViewCxC->hideColumn(0);
ui.tableViewCxC->setItemDelegate(new QSqlRelationalDelegate(ui.tableViewCxC));

I add data with a form (see sreenshots) and the user can submit the data by pressing a save button. When pressing the "add" button i only insert a record in the cxcModel. When the "add" button is pressed the view shows the crop_id but not the crop_name. When i activate the cell or press "save" the right name (via the foreign key) is shown.
From the hidden column of the comboBox i get the crop_id


void BasicDataDialog::on_toolButtonAddCultivar_clicked( )
{
if(!ui.lineEditCultivar->text().isEmpty()){
QSqlRecord rec = cxcModel->record();
QModelIndex idx;
idx = cropModel->index(ui.comboBoxCrop->currentIndex(), 0, QModelIndex());
rec.setNull(0);
rec.setValue(1, cropModel->data(idx).toInt());
rec.setValue(2, ui.lineEditCultivar->text());
if(cxcModel->insertRecord(-1, rec));
ui.pushButtonSave->show();
}
}

Any idea how to force the delegate to show the name (instead of the id) while the data is still cached? thx

janus
5th September 2008, 13:58
it might be a bug (http://trolltech.com/developer/task-tracker/index_html?method=entry&id=176248) ...

hm, has anyone an idea how to work around this?