Good evening boys,
happy holiday! I'm using a QDataWidgetMapper object to map any control of a form to my db table, this is the code:
Qt Code:
  1. mapper = new QDataWidgetMapper(this);
  2. mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
  3. mapper->setModel(mdlLav);
  4. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
  5. mapper->addMapping(ui->lblTipoStamp,mdlLav->fieldIndex("TipoStamp"));
  6. mapper->addMapping(ui->idOrdine, mdlLav->fieldIndex("CodOrd"));
  7. mapper->addMapping(ui->spCapi,mdlLav->fieldIndex("QtaCapi"));
  8. mapper->addMapping(ui->dateTimeEdit, mdlLav->fieldIndex("Data"));
  9. mapper->addMapping(ui->spMetri,mdlLav->fieldIndex("Metri"));
  10. mapper->addMapping(ui->spGrandi, mdlLav->fieldIndex("QtaGrandiO"));
  11. mapper->addMapping(ui->spPiccole, mdlLav->fieldIndex("QtaPiccoleO"));
  12. mapper->addMapping(ui->txtIDBolla,mdlLav->fieldIndex("IDBolla"));
  13. mapper->addMapping(ui->cboTipoSpec,typeIndex);
  14. mapper->addMapping(ui->cboColore,typeIndex2);
  15. mapper->addMapping(ui->cboSpessore,typeIndex3);
  16.  
  17. this->idOrd=idOrd;
  18.  
  19. if (idLav==-1){
  20. mdlLav->insertRow(mdlLav->rowCount());
  21. ui->lblTipoStamp->setText("#-@-*");
  22. mapper->toLast();
  23. Pulisci();
  24. }
  25. else{
  26. for (int i=0; i<mdlLav->rowCount(); i++){
  27. int IdRec= mdlLav->record(i).field("IDLav").value().toInt();
  28. if (IdRec==idLav){
  29. mapper->setCurrentIndex(i);
  30. break;
  31. }
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

The problem is, the new insert of an element work OK, the Edit of an existing element is KO! I check all the field of db and all data are ok, I think it could be near the combobox indexing.

I use connect to check the value selected in combobox to one table, with this function:

Qt Code:
  1. void rtcLavoraOrd::CheckTipoStamp(){
  2.  
  3. ui->cmdConferma->setEnabled(false);
  4. if (!ui->cboColore->currentText().isEmpty() && !ui->cboSpessore->currentText().isEmpty() && !ui->cboTipoSpec->currentText().isEmpty()){
  5. //Verifica della presenza della combinazione scelta
  6. QSqlQuery qry;
  7. qry.exec("SELECT ID FROM TIPISTAMP");
  8.  
  9. bool found=false;
  10.  
  11. while(qry.next()){
  12. if (qry.value(0).toString()==ui->lblTipoStamp->text()){
  13. found=true;
  14. break;
  15. }
  16. }
  17.  
  18. if (!found){
  19.  
  20. ui->fraAlarm->setVisible(true);
  21.  
  22. ui->txtMaxGrandi->setText("(disp.: ###)");
  23. ui->txtMaxPiccole->setText("(disp.: ###)");
  24.  
  25.  
  26. }
  27. else {
  28. QString qry2,colore,tipo,spess;
  29. colore=ui->cboColore->currentText();
  30. tipo=ui->cboTipoSpec->currentText();
  31. spess=ui->cboSpessore->currentText();
  32.  
  33. qry2.clear();
  34.  
  35. qry2=QString("%1%2").arg(totStampateQuery).arg(QString(" WHERE STAMP.Colore='%1' AND STAMP.SPESSORE=%2 AND STAMP.TIPO='%3'").arg(colore).arg(spess).arg(tipo));
  36.  
  37. int maxG=-1,maxP=-1;
  38.  
  39.  
  40. query.clear();
  41. query.exec(qry2);
  42.  
  43. while (query.next()){
  44.  
  45. maxG = query.value(3).toInt();
  46. maxP = query.value(4).toInt();
  47. }
  48.  
  49. //Calcolo dei valori di grandi e piccole
  50.  
  51.  
  52. ui->txtMaxGrandi->setText(QString("(disp.: %1)").arg(maxG));
  53. ui->txtMaxPiccole->setText(QString("(disp.: %1)").arg(maxP));
  54.  
  55. ui->cmdConferma->setEnabled(true);
  56.  
  57. }
  58. }
  59. }
To copy to clipboard, switch view to plain text mode 

It disable the Save button, but not change the mapper.

Any idea?

Thanks for your time.

Michele