I have a QTableWidget which has to display a sql result, tipical situation.
The problem is that in a for cycle, when a row is inserted (composed by 5 items), previouse inserted rows disappear, so the cycle lasts with the table that contains just the last record and the previouse ones are blank... this happen even if I followed the "stardelegate" example...
Any idea about why it is behaving in such a way?
This is the incriminated insertion piece:
(ui.tbwview is the QTableWidget)
[...]
ui.tbwview->setRowCount(0);
ui.tbwview->setRowCount(length);
int i=0;
while(query.next())
{
ui.tbwview->setItem(i,0,id);
ui.tbwview->setItem(i,1,code);
ui.tbwview->setItem(i,2,description);
ui.tbwview->setItem(i,3,um);
ui.tbwview->setItem(i,4,gm);
i++;
}
[...]
ui.tbwview->setRowCount(0);
ui.tbwview->setRowCount(length);
int i=0;
while(query.next())
{
QTableWidgetItem *id=new QTableWidgetItem(query.value(0).toString());
QTableWidgetItem *code=new QTableWidgetItem(query.value(1).toString());
QTableWidgetItem *description=new QTableWidgetItem(query.value(2).toString());
QTableWidgetItem *um=new QTableWidgetItem(query.value(3).toString());
QTableWidgetItem *gm=new QTableWidgetItem(query.value(4).toString());
ui.tbwview->setItem(i,0,id);
ui.tbwview->setItem(i,1,code);
ui.tbwview->setItem(i,2,description);
ui.tbwview->setItem(i,3,um);
ui.tbwview->setItem(i,4,gm);
i++;
}
To copy to clipboard, switch view to plain text mode
Bookmarks