Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (SOLVED) All items identical in QTableWidget
Forum Updated to NodeBB v4.3 + New Features

(SOLVED) All items identical in QTableWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    technovelist
    wrote on last edited by
    #1

    Hi all,

    I'm sure I'm doing something wrong but I can't see what it is.

    First I initialize a QTableWidget as follows:

    @ for (int row = 0; row < ui->AssetTable->rowCount(); ++row)
    for (int column = 0; column < ui->AssetTable->columnCount(); ++column)
    {
    QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(row)+":"+QString::number(column));
    ui->AssetTable->setItem(row, column, newItem);
    }
    @

    When I try to access the items later with this code:

    @ for (int row = 0; row < ui->AssetTable->rowCount(); ++row)
    for (int column = 0; column < ui->AssetTable->columnCount(); ++column)
    {
    QTableWidgetItem *it = ui->AssetTable->item(row, column);
    QString x = it->text();
    }
    @

    all of the items retrieved are the same item. They all exhibit the value "0:0", and if I try to change several of them only the one at 0,0 changes. What am I doing wrong?

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hi.
      Please these two lines
      you didn't set rows and columns of table.
      @ui->AssetTable->setRowCount(5);
      ui->AssetTable->setColumnCount(5);@

      hope this would help.

      Be Cute

      1 Reply Last reply
      0
      • T Offline
        T Offline
        technovelist
        wrote on last edited by
        #3

        Thanks for your answer.
        I did set the row and column count in the form. Do I have to do it in code as well?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          technovelist
          wrote on last edited by
          #4

          Never mind, it's working now although I'm not sure what is different. It's too late to try to figure it out tonight.

          Thanks.

          1 Reply Last reply
          0
          • IamSumitI Offline
            IamSumitI Offline
            IamSumit
            wrote on last edited by
            #5

            Hi.
            Please update your thread title as (SOLVED) at the begining.
            Thank you.

            Be Cute

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved