ui->twMain->insertRow(ui->twMain->rowCount()); row = ui->twMain->rowCount()-1; ui->twMain->setCurrentCell(ui->twMain->rowCount()-1,0); ui->twMain->setItem(row,0,new QTableWidgetItem(QString::number(item.id))); ui->twMain->setItem(row,1,new QTableWidgetItem(item.goodname)); ui->twMain->setItem(row,2,new QTableWidgetItem(QString::number(item.metricid))); ui->twMain->setItem(row,3,new QTableWidgetItem(item.metricname)); QString price = ad->edCount->text();//здесь начинаются проблемы ui->twMain->setItem(row,4,new QTableWidgetItem(price)); ui->twMain->setItem(row,5,new QTableWidgetItem(ad->edPrice->text())); ui->twMain->setItem(row,6,new QTableWidgetItem(ad->edPriceR->text()));//здесь заканчиваются double tmpsumm = ad->edCount->value()*ad->edPrice->value(); QString textF = QString("%1").arg(tmpsumm,0,'f',2); ui->twMain->setItem(row,7,new QTableWidgetItem(textF)); ui->twMain->setItem(row,8,new QTableWidgetItem("-1")); SUMM += tmpsumm; textF = QString("%1").arg(SUMM,0,'f',2); ui->lbSumm->setText(textF);
QTableWidget *tb = (QTableWidget*)sender; QStringList li; tb->clear(); tb->setRowCount(0); tb->setColumnCount(0); QString heder = "Код"; li << heder; heder = "Наименование"; li << heder; heder = "Smid"; li << heder; heder = "Ед.изм"; li << heder; heder = "Кол-во"; li << heder; heder = "Цена"; li << heder; heder = "Розница"; li << heder; heder = "Сумма"; li << heder; heder = "did"; li << heder; int count = li.count(); tb->setColumnCount(count); tb->setHorizontalHeaderLabels(li); tb->setColumnHidden(2,true); tb->setColumnHidden(8,true); tb->setColumnWidth(0,60); if(mid == -1) return 0; QSqlQuery *query = new QSqlQuery(dmModule::db); query->prepare("select did, gid,smid,gname,smname_short,gcount,gprice, gcount*gprice as gsumm, (select max(rg.price) from regprices rg where rg.did = vw.did) as price from VWMDETAILS vw where mid = :mid "); query->bindValue(":mid",mid); query->setForwardOnly(true); query->exec(); summ = 0.0; while(query->next()){ tb->insertRow(tb->rowCount()); tb->setCurrentCell(tb->rowCount()-1,0); tb->setItem(tb->currentRow(),0,new QTableWidgetItem(query->record().value("gid").toString())); tb->setItem(tb->currentRow(),1,new QTableWidgetItem(query->record().value("gname").toString())); tb->setItem(tb->currentRow(),2,new QTableWidgetItem(query->record().value("smid").toString())); tb->setItem(tb->currentRow(),3,new QTableWidgetItem(query->record().value("smname_short").toString())); tb->setItem(tb->currentRow(),4,new QTableWidgetItem(query->record().value("gcount").toString())); tb->setItem(tb->currentRow(),5,new QTableWidgetItem(query->record().value("gprice").toString())); tb->setItem(tb->currentRow(),6,new QTableWidgetItem(query->record().value("price").toString())); summ += query->record().value("gsumm").toDouble(); QString textF = QString("%1").arg(query->record().value("gsumm").toDouble(),0,'f',2); tb->setItem(tb->currentRow(),7,new QTableWidgetItem(textF)); tb->setItem(tb->currentRow(),8,new QTableWidgetItem(query->record().value("did").toString())); } delete query; return 0;
inline QString text() const { return data(Qt::DisplayRole).toString(); }
Покажи код этого диалога. Если у него установлен аттрибут Qt::WA_DeleteOnClose - отсюда и все проблемы.
AddItems *ad = new AddItems(this); ad->lbName->setText(model->record(in.row()).value("gname").toString()); ad->lbSMName->setText(model->record(in.row()).value("smname_short").toString()); ad->edCount->setValue(1.0); if(model->record(in.row()).value("gprice").isNull()) ad->edPrice->setValue(0.0); else ad->edPrice->setValue(model->record(in.row()).value("gprice").toDouble()); if(model->record(in.row()).value("price").isNull()) ad->edPriceR->setValue(0.0); else ad->edPriceR->setValue(model->record(in.row()).value("price").toDouble()); if(ad->exec() != QDialog::Accepted){ delete ad; return; }