HI
I getting data from data base and save it in QList<Storage> listStorage, where
struct Storage{
double Price;
double TaxValue;
int IdItem;
etc...
}
struct Storage{
QString Name;
double Price;
double TaxValue;
int IdItem;
etc...
}
To copy to clipboard, switch view to plain text mode
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
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->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)));
}
To copy to clipboard, switch view to plain text mode
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
To copy to clipboard, switch view to plain text mode
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.
Bookmarks