PDA

View Full Version : [SOLVED] QTableWidget can not add item correctly



porterneon
1st August 2011, 17:49
HI
I getting data from data base and save it in QList<Storage> listStorage, where

struct Storage{
QString Name;
double Price;
double TaxValue;
int IdItem;
etc...
}
This is how I'm feeding list of storage

for(int i = 0; i < records.count(); i++)
{
Storage st;
st.Name = records[i].value("Name").toString();
st.Price = records[i].value("Price").toDouble();
st.TaxValue = records[i].value("TaxValue").toDouble();

listStorage.append(st);
}

At the end, when all sql queries are executed, I'm trying to feed my QTableWidget:


ui->tblStorage->setRowCount(records.count());
for(int i = 0; i < records.count(); i++){
ui->tblStorage->setItem(i,0, new QTableWidgetItem(listStorage.at(i).Name));
ui->tblStorage->setItem(i,1, new QTableWidgetItem(QString::number(listStorage.at(i) .TaxValue)));
...
ui->tblStorage->setItem(i,7, new QTableWidgetItem(QString::number(listStorage.at(i) .Price)));
}


All columns are being inserted correctly, bu on one "Price" I'm getting error:

QTableWidget: cannot insert an item that is already owned by another QTableWidget

What is wrong?


PS: I found the issue. I have method that is being executed when one of cell in table change value.
This method is recalculating items and makes this error.