Hi,
I have a QTableWidget in my app which gets updated every second. PFB the code which performs the updation:
QStringList detstatsList
= lStr2.
split("|");
//The list contains data to be loaded into the table int row = 0;
ui.trafficStatsTable->setRowCount(0);//This line seems to be causing the problem :S
for (int m = 0; m < detstatsList.size(); ++m) {
if(m%4 == 0)
{
row = ui.trafficStatsTable->rowCount();
ui.trafficStatsTable->insertRow(row);
ui.trafficStatsTable->setItem(row, 0, resourceItem);
}
if(m%4 == 1)
ui.trafficStatsTable->setItem(row, 1, resourceItem);
if(m%4 == 2)
ui.trafficStatsTable->setItem(row, 2, resourceItem);
if(m%4 == 3)
ui.trafficStatsTable->setItem(row, 3, resourceItem);
//delete resourceItem;
}
QStringList detstatsList = lStr2.split("|");//The list contains data to be loaded into the table
int row = 0;
ui.trafficStatsTable->setRowCount(0);//This line seems to be causing the problem :S
for (int m = 0; m < detstatsList.size(); ++m) {
QTableWidgetItem *resourceItem = new QTableWidgetItem(detstatsList[m]);
if(m%4 == 0)
{
row = ui.trafficStatsTable->rowCount();
ui.trafficStatsTable->insertRow(row);
ui.trafficStatsTable->setItem(row, 0, resourceItem);
}
if(m%4 == 1)
ui.trafficStatsTable->setItem(row, 1, resourceItem);
if(m%4 == 2)
ui.trafficStatsTable->setItem(row, 2, resourceItem);
if(m%4 == 3)
ui.trafficStatsTable->setItem(row, 3, resourceItem);
//delete resourceItem;
}
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):
(gdb) bt
#0 0x00a08402 in __kernel_vsyscall ()
#1 0x41a9bfa0 in raise () from /lib/libc.so.6
#2 0x41a9d8b1 in abort () from /lib/libc.so.6
#3 0x41ad2ebb in __libc_message () from /lib/libc.so.6
#4 0x41adaf41 in _int_free () from /lib/libc.so.6
#5 0x41ade580 in free () from /lib/libc.so.6
#6 0x00abd0a1 in operator delete () from /usr/lib/libstdc++.so.6
#7 0x0076636b in QTableWidgetItem::~QTableWidgetItem$delete () from /usr/lib/libQtGui.so.4
#8 0x007668fd in QTableModel::removeRows () from /usr/lib/libQtGui.so.4
#9 0x00762e1e in QTableModel::setRowCount () from /usr/lib/libQtGui.so.4
#10 0x00769ee4 in QTableWidget::setRowCount () from /usr/lib/libQtGui.so.4
#11 0x0806e721 in Dialog::carryOutUpdate ()
(gdb) bt
#0 0x00a08402 in __kernel_vsyscall ()
#1 0x41a9bfa0 in raise () from /lib/libc.so.6
#2 0x41a9d8b1 in abort () from /lib/libc.so.6
#3 0x41ad2ebb in __libc_message () from /lib/libc.so.6
#4 0x41adaf41 in _int_free () from /lib/libc.so.6
#5 0x41ade580 in free () from /lib/libc.so.6
#6 0x00abd0a1 in operator delete () from /usr/lib/libstdc++.so.6
#7 0x0076636b in QTableWidgetItem::~QTableWidgetItem$delete () from /usr/lib/libQtGui.so.4
#8 0x007668fd in QTableModel::removeRows () from /usr/lib/libQtGui.so.4
#9 0x00762e1e in QTableModel::setRowCount () from /usr/lib/libQtGui.so.4
#10 0x00769ee4 in QTableWidget::setRowCount () from /usr/lib/libQtGui.so.4
#11 0x0806e721 in Dialog::carryOutUpdate ()
To copy to clipboard, switch view to plain text mode
Bookmarks