Good day to all,
I know this issue has been posted before but i could not find a suitable answer.
The problem is this :
I have a QDataWidgetMapper with the model set to a QSortFilterProxyModel that filters a QSqlRelationalTableModel.
filter->setSourceModel(model);
model->setTable("patients");
model
->setRelation
(3,
QSqlRelation("doctors",
"doctor_id",
"doctor_name"));
model->select();
model= new QSqlRelationalTableModel(this);
filter= new QSortFilterProxyModel(this);
filter->setSourceModel(model);
model->setTable("patients");
model->setRelation(3,QSqlRelation("doctors","doctor_id","doctor_name"));
model->select();
To copy to clipboard, switch view to plain text mode
the data stored in the model comes from a" medical patients " tabel in witch the a field doctor_id is linked to primary key in doctors table like this
patients table :
================================================== =======
name [text] |condition [text] | treatment [text] |doctor_id [integer]
================================================== =======
doctors table:
==============================
doctor_id[integer] | doctor_name [text]
==============================
It's pretty straight forward right.
I filter the model by field name to make make the user's selection easier
Next I apply a mapper:
mapper->setModel(filter);
mapper = new QDataWidgetMapper(this);
mapper->setModel(filter);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
To copy to clipboard, switch view to plain text mode
I mapped all other field to text edit widgets but I needed a combo box to select a doctor_name
QSqlTableModel* doctors
= model
->relationModel
(model
->fieldIndex
("doctor_id "));
comboBox->setModel(tabelMedici);
comboBox->setModelColumn(tabelMedici->fieldIndex("doctor_name"));//populates the combo box with the names
mapper->addMapping(comboBox,model->fieldIndex("doctor_id "));
QSqlTableModel* doctors= model->relationModel(model->fieldIndex("doctor_id "));
comboBox->setModel(tabelMedici);
comboBox->setModelColumn(tabelMedici->fieldIndex("doctor_name"));//populates the combo box with the names
mapper->addMapping(comboBox,model->fieldIndex("doctor_id "));
To copy to clipboard, switch view to plain text mode
Finaly i need to navigate the model in a tableViewer
tableView->setModel(filter);
tableView->setModel(filter);
connect(tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
mapper, SLOT(setCurrentModelIndex(QModelIndex)));
To copy to clipboard, switch view to plain text mode
when i do a selection in tableView all the text widgets change values in accordance except comboBox witch doesn't change anything.
The combo box gets populated but is doesn't automatically change selection to the relevant field value.
What am I missing here?
Any suggestions?
Bookmarks