PDA

View Full Version : QDataWidgetMapper refresh error



cia.michele
17th August 2011, 21:22
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:


mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setModel(mdlLav);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->lblTipoStamp,mdlLav->fieldIndex("TipoStamp"));
mapper->addMapping(ui->idOrdine, mdlLav->fieldIndex("CodOrd"));
mapper->addMapping(ui->spCapi,mdlLav->fieldIndex("QtaCapi"));
mapper->addMapping(ui->dateTimeEdit, mdlLav->fieldIndex("Data"));
mapper->addMapping(ui->spMetri,mdlLav->fieldIndex("Metri"));
mapper->addMapping(ui->spGrandi, mdlLav->fieldIndex("QtaGrandiO"));
mapper->addMapping(ui->spPiccole, mdlLav->fieldIndex("QtaPiccoleO"));
mapper->addMapping(ui->txtIDBolla,mdlLav->fieldIndex("IDBolla"));
mapper->addMapping(ui->cboTipoSpec,typeIndex);
mapper->addMapping(ui->cboColore,typeIndex2);
mapper->addMapping(ui->cboSpessore,typeIndex3);

this->idOrd=idOrd;

if (idLav==-1){
mdlLav->insertRow(mdlLav->rowCount());
ui->lblTipoStamp->setText("#-@-*");
mapper->toLast();
Pulisci();
}
else{
for (int i=0; i<mdlLav->rowCount(); i++){
int IdRec= mdlLav->record(i).field("IDLav").value().toInt();
if (IdRec==idLav){
mapper->setCurrentIndex(i);
break;
}
}
}


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:



void rtcLavoraOrd::CheckTipoStamp(){

ui->cmdConferma->setEnabled(false);
if (!ui->cboColore->currentText().isEmpty() && !ui->cboSpessore->currentText().isEmpty() && !ui->cboTipoSpec->currentText().isEmpty()){
//Verifica della presenza della combinazione scelta
QSqlQuery qry;
qry.exec("SELECT ID FROM TIPISTAMP");

bool found=false;

while(qry.next()){
if (qry.value(0).toString()==ui->lblTipoStamp->text()){
found=true;
break;
}
}

if (!found){

ui->fraAlarm->setVisible(true);

ui->txtMaxGrandi->setText("(disp.: ###)");
ui->txtMaxPiccole->setText("(disp.: ###)");


}
else {
QString qry2,colore,tipo,spess;
colore=ui->cboColore->currentText();
tipo=ui->cboTipoSpec->currentText();
spess=ui->cboSpessore->currentText();

qry2.clear();

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));

int maxG=-1,maxP=-1;


query.clear();
query.exec(qry2);

while (query.next()){

maxG = query.value(3).toInt();
maxP = query.value(4).toInt();
}

//Calcolo dei valori di grandi e piccole


ui->txtMaxGrandi->setText(QString("(disp.: %1)").arg(maxG));
ui->txtMaxPiccole->setText(QString("(disp.: %1)").arg(maxP));

ui->cmdConferma->setEnabled(true);

}
}
}


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

Any idea?

Thanks for your time.

Michele

wysota
18th August 2011, 02:20
What is the problem?