Hi,

I have a QTableWidget in my app which gets updated every second. PFB the code which performs the updation:
Qt Code:
  1. QStringList detstatsList = lStr2.split("|");//The list contains data to be loaded into the table
  2. int row = 0;
  3. ui.trafficStatsTable->setRowCount(0);//This line seems to be causing the problem :S
  4. for (int m = 0; m < detstatsList.size(); ++m) {
  5. QTableWidgetItem *resourceItem = new QTableWidgetItem(detstatsList[m]);
  6. if(m%4 == 0)
  7. {
  8. row = ui.trafficStatsTable->rowCount();
  9. ui.trafficStatsTable->insertRow(row);
  10. ui.trafficStatsTable->setItem(row, 0, resourceItem);
  11. }
  12. if(m%4 == 1)
  13. ui.trafficStatsTable->setItem(row, 1, resourceItem);
  14. if(m%4 == 2)
  15. ui.trafficStatsTable->setItem(row, 2, resourceItem);
  16. if(m%4 == 3)
  17. ui.trafficStatsTable->setItem(row, 3, resourceItem);
  18. //delete resourceItem;
  19. }
To copy to clipboard, switch view to plain text mode 
The program crashed out after few updates. The backtrace from gdb is given below. I am not able to figure out why removing rows is leading to a memory trouble. Could someone please help?

Backtrace(starting from the function call containing above code):
Qt Code:
  1. (gdb) bt
  2. #0 0x00a08402 in __kernel_vsyscall ()
  3. #1 0x41a9bfa0 in raise () from /lib/libc.so.6
  4. #2 0x41a9d8b1 in abort () from /lib/libc.so.6
  5. #3 0x41ad2ebb in __libc_message () from /lib/libc.so.6
  6. #4 0x41adaf41 in _int_free () from /lib/libc.so.6
  7. #5 0x41ade580 in free () from /lib/libc.so.6
  8. #6 0x00abd0a1 in operator delete () from /usr/lib/libstdc++.so.6
  9. #7 0x0076636b in QTableWidgetItem::~QTableWidgetItem$delete () from /usr/lib/libQtGui.so.4
  10. #8 0x007668fd in QTableModel::removeRows () from /usr/lib/libQtGui.so.4
  11. #9 0x00762e1e in QTableModel::setRowCount () from /usr/lib/libQtGui.so.4
  12. #10 0x00769ee4 in QTableWidget::setRowCount () from /usr/lib/libQtGui.so.4
  13. #11 0x0806e721 in Dialog::carryOutUpdate ()
To copy to clipboard, switch view to plain text mode