I have a qdatawidgetmapper which I use to browse through data from a specific table in MySQL.

Qt Code:
  1. // Setup the model to use in the mapper
  2. model = new QSqlRelationalTableModel(this);
  3. model->setTable("Customers");
  4. model->select();
  5.  
  6. // Setup the mapper for the product widgets
  7. mapper = new QDataWidgetMapper(this);
  8. mapper->setModel(model);
  9. mapper->addMapping(ui->cNumLineEdit, 0);
  10. mapper->addMapping(ui->nameLineEdit, 1);
  11. mapper->addMapping(ui->frequencyComboBox, 2, "currentIndex");
  12. mapper->addMapping(ui->priorityComboBox, 3, "currentIndex");
  13. mapper->addMapping(ui->typeComboBox, 4, "currentIndex");
  14. mapper->addMapping(ui->address1LineEdit, 5);
  15. mapper->addMapping(ui->address2LineEdit,6);
  16. mapper->addMapping(ui->cityLineEdit,7);
  17. mapper->addMapping(ui->postalCodeLineEdit,8);
  18. mapper->addMapping(ui->telephoneLineEdit,9);
To copy to clipboard, switch view to plain text mode 

I try to create a new record and it creates normally but the primary key is an autoincrement number provided from MySQL. I would like to refresh the record to include the number in the form. I believe that not having the value produces errors when trying to save data or add other data which are related to the new record.

Qt Code:
  1. void Customers::on_newPushButton_clicked()
  2. {
  3. // Create a new item and clear all widgets
  4. QSqlRecord sqlRecord1;
  5. model->insertRecord(-1,sqlRecord1);
  6.  
  7. ui->cNumLineEdit->clear();
  8. ui->nameLineEdit->clear();
  9. ui->address1LineEdit->clear();
  10. ui->address2LineEdit->clear();
  11. ui->cityLineEdit->clear();
  12. ui->postalCodeLineEdit->clear();
  13. ui->telephoneLineEdit->clear();
  14. mapper->toLast();
  15. }
To copy to clipboard, switch view to plain text mode 

Can anyone tell me if I am doing it correctly or if I need to insert the record and retrieve it in a different way?

Thanks,

Pericles