Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QTableWidget update items.

    General and Desktop
    1
    1
    2053
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      Overflowz last edited by

      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?
      1 Reply Last reply Reply Quote 0
      • First post
        Last post