Results 1 to 2 of 2

Thread: QDataWidgetMapper refresh error

  1. #1
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDataWidgetMapper refresh error

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataWidgetMapper refresh error

    What is the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDataWidgetmapper
    By locus in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2012, 11:24
  2. Advise:Do I need QDataWidgetMapper?
    By fatecasino in forum Newbie
    Replies: 1
    Last Post: 4th March 2011, 01:04
  3. Replies: 2
    Last Post: 14th January 2011, 15:09
  4. QDataWidgetMapper and QSplitter
    By pippo42 in forum Qt Programming
    Replies: 0
    Last Post: 28th January 2010, 13:21
  5. QDataWidgetMapper
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 24th March 2009, 19:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.