[Qt-interest] Valgrind indicates memory leak in QTableWidget

Philipp Münzel mailing-lists at philippmuenzel.de
Wed Jul 6 23:57:49 CEST 2011


Hi folks,

according to the documentation, QTableWidget::setItem ( int row, int column, QTableWidgetItem * item )
"The table takes ownership of the item."


>From that I assume that when I toss "new"-allocated QTableWidgetItems into the TableWidget, the TableWidget will take care of deleting them.

However, when using the Analyzer of QtCreator the valgrind output states:
"2,816 (768 direct, 2,048 indirect) bytes in 32 blocks are definitely lost in loss record 191 of 210
  in Router::updateTable() in src/router.cpp:184
  1: operator new(unsigned int) in /usr/lib64/valgrind/vgpreload_memcheck-x86-linux.so
  2: Router::updateTable() in ..."

The line in question reads
QTableWidgetItem* newItem = new QTableWidgetItem(QString::fromStdString(route_[i].id()));
ui->tableWidget->setItem(i, 0, newItem);

What am I missing? Do I need a special "cleanup" call for the TableWidget? Or does valgrind miss things that Qt does internally?

Regards,
Philipp



More information about the Qt-interest-old mailing list