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]Doesn't QTableWidgetItems create memory leaks
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Doesn't QTableWidgetItems create memory leaks

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.9k 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.
  • A Offline
    A Offline
    adnan
    wrote on last edited by
    #1

    We usually add items to QTableWidget in this manner
    @QTableWidgetItem *item0 = new QTableWidgetItem();
    QTableWidgetItem *item1 = new QTableWidgetItem();
    ui->tableWidget->setItem(m, 0, item0);
    ui->tableWidget->setItem(m, 1, item1);
    item0->setText("entry1");
    item1->setText("entry2");@

    Now, if suppose we clear the table
    @ui->tableWidget->clearContents();@
    And again execute the code for displaying entry, new items will be created for displaying. Creating memory leaks, as there we did not delete the item1 and item2

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      If you actually look at the implementation file of "qtablewidget.cpp":http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/itemviews/qtablewidget.cpp

      it actually deletes the items.

      @void QTableModel::clearContents()
      {
      for (int i = 0; i < tableItems.count(); ++i) {
      if (tableItems.at(i)) {
      tableItems.at(i)->view = 0;
      delete tableItems.at(i);
      tableItems[i] = 0;
      }

      }  
      reset();  
      

      } @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adnan
        wrote on last edited by
        #3

        Thanks a lot! I was really concerned over this issue

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          You are welcome.

          Regards
          Soumitra.

          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