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.

    1. at first insertion = OK, all first cells are filled.
    2. updating firstly inserted items = OK, all first cells are updated.
    3. at second insertion = OK, all second cells are filled.
    4. updating second inserted items = OK, all second cells are updated.
    5. updating first inserted items = FAIL, all first cells are updated, but NEXT cell's first table is empty. WHY?

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.