Hi!

As the title suggests, I'm attempting to get the selected value from a QComboBox on a wizard page. I have a bunch of combo-boxes which are populated with data from a relational model's relations. I was struggling trying to insert a record into the database with the selected values and have discovered that calling value() is returning the currentIndex of the combo-boxes, rather than the selected value.

I should point out here that I'm both very new to Qt and C++, so go easy on me.

My code thus far:

The Patient object is derived from QSqlRelationalTableModel. I have a bunch of methods in that class to return the relations of the model, hence the "patient->gender()" type calls. They return a object of type QSqlRelation.

Qt Code:
  1. /***
  2.  * Register all of the necessary fields with this
  3.  * wizard form page.
  4.  */
  5. void NewPatientPageTwo::registerFields()
  6. {
  7. registerField("doctor", ui->doctor);
  8. registerField("gender", ui->gender);
  9. registerField("sexual_orientation", ui->sexual_orientation);
  10. registerField("marital_status", ui->marital_status);
  11. registerField("employment_status", ui->employment_status);
  12. registerField("performance_status", ui->performance_status);
  13. registerField("alcohol_consumption", ui->alcohol_consumption);
  14. registerField("clinical_group", ui->clinical_group);
  15. registerField("ethnic_category", ui->ethnic_category);
  16. }
  17.  
  18. /***
  19.  * Each of the fields on this wizard page are
  20.  * combo-boxes that need to be populated with
  21.  * information held in the database.
  22.  */
  23. void NewPatientPageTwo::populateFields()
  24. {
  25. Patient *patientModel = new Patient(this);
  26.  
  27. // doctor
  28. ui->doctor->setModel(patientModel->doctor());
  29. ui->doctor->setModelColumn(patientModel->doctor()->fieldIndex("lastname"));
  30.  
  31. // gender
  32. ui->gender->setModel(patientModel->gender());
  33. ui->gender->setModelColumn(patientModel->gender()->fieldIndex("description"));
  34.  
  35. // sexual orientation
  36. ui->sexual_orientation->setModel(patientModel->sexualOrientation());
  37. ui->sexual_orientation->setModelColumn(patientModel->sexualOrientation()->fieldIndex("description"));
  38.  
  39. // marital status
  40. ui->marital_status->setModel(patientModel->maritalStatus());
  41. ui->marital_status->setModelColumn(patientModel->maritalStatus()->fieldIndex("description"));
  42.  
  43. // employment status
  44. ui->employment_status->setModel(patientModel->employmentStatus());
  45. ui->employment_status->setModelColumn(patientModel->employmentStatus()->fieldIndex("description"));
  46.  
  47. // performance status
  48. ui->performance_status->setModel(patientModel->performanceStatus());
  49. ui->performance_status->setModelColumn(patientModel->performanceStatus()->fieldIndex("description"));
  50.  
  51. // alcohol consumption
  52. ui->alcohol_consumption->setModel(patientModel->alcoholStatus());
  53. ui->alcohol_consumption->setModelColumn(patientModel->alcoholStatus()->fieldIndex("description"));
  54.  
  55. // clinical group
  56. ui->clinical_group->setModel(patientModel->clinicalGroup());
  57. ui->clinical_group->setModelColumn(patientModel->clinicalGroup()->fieldIndex("description"));
  58.  
  59. // ethnic category
  60. ui->ethnic_category->setModel(patientModel->ethnicCategory());
  61. ui->ethnic_category->setModelColumn(patientModel->ethnicCategory()->fieldIndex("description"));
  62. }
To copy to clipboard, switch view to plain text mode 

This is the imlpementation of the accept method in the wizard class. It's called when I hit the finish button.
Qt Code:
  1. void NewPatient::accept()
  2. {
  3. Patient *model = new Patient(this);
  4. unsigned int row = model->rowCount();
  5.  
  6. if (model->insertRow(row)) {
  7. model->setData(model->index(row, Patient::NHSNumber), field("nhsnumber"));
  8. model->setData(model->index(row, Patient::EmploymentStatus), field("employment_status"));
  9. model->setData(model->index(row, Patient::Gender), field("gender"));
  10. model->setData(model->index(row, Patient::MaritalStatus), field("marital_status"));
  11. model->setData(model->index(row, Patient::PerformanceStatus), field("performance_status"));
  12. model->setData(model->index(row, Patient::SexualOrientation), field("sexual_orientation"));
  13. model->setData(model->index(row, Patient::ClinicalGroup), field("clinical_group"));
  14. model->setData(model->index(row, Patient::EthnicCategory), field("ethnic_category"));
  15. model->setData(model->index(row, Patient::AlcoholStatus), field("alcohol_consumption"));
  16. model->setData(model->index(row, Patient::Doctor), field("doctor"));
  17. model->setData(model->index(row, Patient::Salutation), field("title"));
  18. model->setData(model->index(row, Patient::BirthDate), field("dob").toDate().toString(Qt::ISODate));
  19. model->setData(model->index(row, Patient::FirstName), field("firstname"));
  20. model->setData(model->index(row, Patient::LastName), field("lastname"));
  21. model->setData(model->index(row, Patient::RegisteredDate), QDate::currentDate().toString(Qt::ISODate));
  22.  
  23. model->database().transaction();
  24.  
  25. if (model->submitAll()) {
  26. model->database().commit();
  27. } else {
  28. model->database().rollback();
  29. }
  30. }
  31.  
  32. close();
  33. }
To copy to clipboard, switch view to plain text mode 

The insert is failing because the calls to field("inputname") aren't returning the value, as expected. They're returning the currentIndex. Any help would be really appreciated.

Thanks!