QTreewidget clear creates memory leaks
Hi,
I am using Qtreewideget.I have to add Qtreewidgetitem in tree widget at runtime.After a period I clear tree wideget by using clear() funtion (also try using delete explictly).
But its seems memory doesnt released.Its kept on increasing.
Since my process is periodic.Applcation hang after some time
Please suggest
Re: QTreewidget clear creates memory leaks
There are lot of people using QTreeWidgetItems / QTreeWidget without problems ( including me ), so this is probably problem with your code. Show the code, maybe someone will help you.
Re: QTreewidget clear creates memory leaks
Hi ,
Please check given function.Its call after 3 sec periodically.
Please let me know where i am wrong
Code:
void MainWindow
::parseMainscreen(QString mainstring
) {
if(mainstring!="")
{
if(arrVisDetails.count!=0)
ui->Monitor_tree->clear();
for(int i=0; i<arrVisDetails .count(); i++)
{
qtreewidgetitem1->setText(0,arrVisDetails .at(i));
ui->Monitor_tree->addTopLevelItem(qtreewidgetitem1);
}
}
}
Thanks
Re: QTreewidget clear creates memory leaks
So if you delete items manually like this:
Code:
void MainWindow
::ParseMainscreen(QString mainstring
){ if(mainstring!=""){
const int count = arrVisDetails.count();
if( count ){
for( int i=ui->Monitor_tree->topLevelItemCount()-1; i>=0 ; --i ){
delete ui->Monitor_tree->takeTopLevelItem(i);
}
for( int i=0 ; i<count ; ++i ){
item->setText(0,arrVisDetails .at(i));
ui->Monitor_tree->addTopLevelItem(item);
}
}
}
}
memory still leaks ? This method looks ok (I assume that arrVisDetails.count!=0 is a typo), are you sure you are not doing something else in your code ?
Try to separate this method into another small app, this way you can see if its this method that leaks.
Re: QTreewidget clear creates memory leaks
Why do you think its your tree that is leaking?
Don't you allocate anything else on the heap?
Re: QTreewidget clear creates memory leaks
Re: QTreewidget clear creates memory leaks
clear() deletes all the items in the widget, there is no leak here.