So what I am trying to do it map data from a model to various widgets in a form (combo boxes, spin boxes, etc.). I would like the user to be able to change the index of one of the combo boxes (the "name" combo box) and have the rest of the widgets change accordingly. I am able to accomplish this with a table view by connecting the index of the mapper with the index of the table view; however, if I remove try to use the combo box as the primary means of changing the index, the index of the "name" combo box reverts to 0 as soon as I select another widget. Other than this, it seems to be working as it should. The other widgets in the form will also need to be used to edit the data. Any help is greatly appreciated. The following code is stripped down significantly.

Qt Code:
  1. ui->setupUi(this);
  2.  
  3. // Create the data model
  4. model = new QSqlRelationalTableModel(ui->personList);
  5. model->setEditStrategy(QSqlTableModel::OnFieldChange);
  6. model->setTable("people");
  7. model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
  8.  
  9. // Remember the indexes of the columns
  10. genderIdx = model->fieldIndex("gender");
  11.  
  12. // Set the relations to the other database tables
  13. model->setRelation(genderIdx, QSqlRelation("gender", "genderid", "gender"));
  14.  
  15. // Populate the model
  16. if (!model->select()) {
  17. showError(model->lastError());
  18. return;
  19. }
  20.  
  21. //QSqlTableModel *relModel = model->relationModel(nameIdx);
  22.  
  23.  
  24. // Set the model and hide the ID column
  25. ui->personList->setModel(model);
  26. ui->personList->setColumnHidden(0, true);
  27. ui->personList->setSelectionMode(QAbstractItemView::SingleSelection);
  28.  
  29. // Initialize the Combo Boxes
  30. ui->nameCBox->setModel(model);
  31. ui->nameCBox->setModelColumn(model->fieldIndex("name"));
  32.  
  33. ui->genderCBox->setModel(model->relationModel(genderIdx));
  34. ui->genderCBox->setModelColumn(model->relationModel(genderIdx)->fieldIndex("gender"));
  35.  
  36.  
  37.  
  38. //Create Mapper
  39. QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
  40. mapper->setModel(model);
  41. mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
  42. mapper->addMapping(ui->nameCBox, model->fieldIndex("name"));
  43. mapper->addMapping(ui->genderCBox, model->fieldIndex("gender"));
  44.  
  45.  
  46. //*********************************************************//
  47.  
  48. connect(ui->insertButton, SIGNAL(clicked()),
  49. this, SLOT(insertPerson()));
  50.  
  51. connect(ui->nameCBox, SIGNAL(currentIndexChanged(int)),
  52. mapper, SLOT(setCurrentIndex(int)));
  53.  
  54. connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
  55.  
  56.  
  57. ui->nameCBox->setCurrentIndex(0);
  58. mapper->setCurrentIndex(0);
To copy to clipboard, switch view to plain text mode