Hello to everybody,
I read some post on this forum but i didn't found any answer to my problem. I hope you could help me
I've a table (Carichi) with a Foreing key of an other table (Colori), so I create my QSqlRelationalTableModel;
//Definizione del modello principale
myModel->setTable("Carichi");
//Definizione del modello principale
myModel = new QSqlRelationalTableModel(this);
myModel->setTable("Carichi");
myModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
To copy to clipboard, switch view to plain text mode
Now I create the relationModel to a new QSqlTableModel:
int custIndexCol=myModel->fieldIndex("CodCol");
myModel
->setRelation
(custIndexCol,
QSqlRelation("Colori",
"idColori",
"Colore"));
//Definizione del modello del colore
mdlCol = myModel->relationModel(custIndexCol);
ui->cboColore->setModel(mdlCol);
ui->cboColore->setModelColumn(mdlCol->fieldIndex("Colore"));
int custIndexCol=myModel->fieldIndex("CodCol");
myModel->setRelation(custIndexCol,QSqlRelation("Colori","idColori","Colore"));
//Definizione del modello del colore
mdlCol = myModel->relationModel(custIndexCol);
mdlCol->setEditStrategy(QSqlTableModel::OnManualSubmit);
ui->cboColore->setModel(mdlCol);
ui->cboColore->setModelColumn(mdlCol->fieldIndex("Colore"));
ui->cboColore->setItemDelegate(new QSqlRelationalDelegate(ui->cboColore));
To copy to clipboard, switch view to plain text mode
Now I've all my components (also a QComboBox to display items).
Now I'd like that the user can edit the QComboBox (setting it editable isn't it?) also adding a new element (that not is into Colori) and adding it to base table Colori, so it create the element for the foreign key and the table Carichi can save the new element created.
I thought that setting QComboBox editable could be enought, seen the model linked by setModel(), but, I understood that isn't!!
I hope I explain correctly enought my problem
Thanks a lot for your time
Michele
Bookmarks