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:

Qt Code:
  1. model->setTable("tili");
  2. model->setRelation(3, QSqlRelation("alv", "id", "prosentti"));
  3. model->setRelation(4, QSqlRelation("vast", "id", "rooli"));
  4. model->select();
  5.  
  6. tiliView->setModel(model);
  7. tiliView->setItemDelegate(new QSqlRelationalDelegate(tiliView));
To copy to clipboard, switch view to plain text mode 

Lisaa:

Qt Code:
  1. void TiliWindow::lisaa()
  2. {
  3. int r = model->rowCount();
  4. model->insertRows(r, 1);
  5. QModelIndex index = model->index(r,1);
  6. tiliView->setCurrentIndex(index);
  7.  
  8. tiliView->edit(index);
To copy to clipboard, switch view to plain text mode