PDA

View Full Version : QTableView & QSqlRelationalTableModel



jippo
8th March 2007, 20:41
I have the following code. Only first of those relations have default value in combobox in the tableview in lisaa function. Only difference between those relations is, "prosentti" is integer, and "rooli" is text. I'm using SQLITE backend.

I need to have a default value also in the second, "rooli", relation. But no go.

Constructor:



model = new QSqlRelationalTableModel();
model->setTable("tili");
model->setRelation(3, QSqlRelation("alv", "id", "prosentti"));
model->setRelation(4, QSqlRelation("vast", "id", "rooli"));
model->select();

tiliView->setModel(model);
tiliView->setItemDelegate(new QSqlRelationalDelegate(tiliView));


Lisaa:



void TiliWindow::lisaa()
{
int r = model->rowCount();
model->insertRows(r, 1);
QModelIndex index = model->index(r,1);
tiliView->setCurrentIndex(index);

tiliView->edit(index);

jpn
27th March 2007, 21:40
Did you manage to solve the problem yet? I'm pretty sure debugging through QSqlRelationalDelegate::createEditor() would help (especially the line which sets the model column for the combo box).