Hello all,

I am trying to populate two combo boxes from another relation using the code below:

Qt Code:
  1. // Setup the model to use in the mapper
  2. model = new QSqlRelationalTableModel(this);
  3. model->setTable("Orders");
  4. model->setRelation(7, QSqlRelation("customers", "CustomerNumber", "Name"));
  5. model->setRelation(5, QSqlRelation("employee", "EmployeeNumber", "UserName"));
  6. model->select();
  7. Qt::SortOrder order = Qt::AscendingOrder;
  8. model->sort(0, order);
  9.  
  10. // Setup the mapper for the order widgets
  11. mapper = new QDataWidgetMapper(this);
  12. mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
  13. mapper->setModel(model);
  14. mapper->setItemDelegate(new QSqlRelationalDelegate(model));
  15. mapper->addMapping(ui->idLineEdit, 0);
  16. mapper->addMapping(ui->fullfilledCheckBox,1);
  17. mapper->addMapping(ui->fullfilledDateEdit, 2);
  18. mapper->addMapping(ui->orderDateEdit, 3);
  19. mapper->addMapping(ui->dueDateEdit, 4);
  20. mapper->addMapping(ui->employeeComboBox, 5, "currentIndex");
  21. mapper->addMapping(ui->dueTimeEdit, 6);
  22. mapper->addMapping(ui->customerComboBox, 7, "currentIndex");
To copy to clipboard, switch view to plain text mode 

The attribute names and numbers are correct. The orders relation has employee number in column 5 and customer number in column 7. The code runs and shows the order mapped correctly but the combo boxes are empty.

Any idea why this is happening?

Thanks,

Pericles