QTableWidget update items.
-
Hi, I'm having trouble with updating QTableWidgetItems. I don't understand what I'm doing wrong :(
[code]void MainWindow::fillTable(QList<QByteArray> Info)
{
int Row = ui->clientsList->rowCount() - 1; //Starts from 0.//Check if client row already exists. for(int i = Row; i >= 0; i--) { if(ui->clientsList->item(i, 0)->text().contains(QString(Info[1]))) { //Update row. for(int u = 0; u < Info.count() - 1; u++) { ui->clientsList->setItem(i, u, new QTableWidgetItem(QString(Info[u + 1]))); } return; //avoid new row insertion. } } //Insert new row. Row = ui->clientsList->rowCount() + 1; ui->clientsList->setRowCount(Row); for(int i = 0; i < Info.count() - 1; i++) { //Fill rows. ui->clientsList->setItem(Row - 1, i, new QTableWidgetItem(QString(Info[i + 1]))); }
}[/code]
Step by step problem.
- at first insertion = OK, all first cells are filled.
- updating firstly inserted items = OK, all first cells are updated.
- at second insertion = OK, all second cells are filled.
- updating second inserted items = OK, all second cells are updated.
- updating first inserted items = FAIL, all first cells are updated, but NEXT cell's first table is empty. WHY?