Results 1 to 7 of 7

Thread: QTreewidget clear creates memory leaks

  1. #1
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default 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

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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.

  3. The following user says thank you to stampede for this useful post:

    moh.gup@gmail.com (1st April 2011)

  4. #3
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default 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

    Qt Code:
    1. void MainWindow::parseMainscreen(QString mainstring)
    2. {
    3. if(mainstring!="")
    4. {
    5. QStringList arrVisDetails = QString(mainstring).split("<fld>",QString::KeepEmptyParts,Qt::CaseInsensitive);
    6. if(arrVisDetails.count!=0)
    7. ui->Monitor_tree->clear();
    8.  
    9. for(int i=0; i<arrVisDetails .count(); i++)
    10. {
    11. qtreewidgetitem1= new QTreeWidgetItem();
    12. qtreewidgetitem1->setText(0,arrVisDetails .at(i));
    13. ui->Monitor_tree->addTopLevelItem(qtreewidgetitem1);
    14. }
    15.  
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Last edited by wysota; 1st April 2011 at 18:59. Reason: reformatted to look better

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTreewidget clear creates memory leaks

    So if you delete items manually like this:
    Qt Code:
    1. void MainWindow::ParseMainscreen(QString mainstring){
    2. if(mainstring!=""){
    3. QStringList arrVisDetails = QString(mainstring).split("<fld>",QString::KeepEmptyParts,Qt::CaseInsensitive);
    4. const int count = arrVisDetails.count();
    5. if( count ){
    6. for( int i=ui->Monitor_tree->topLevelItemCount()-1; i>=0 ; --i ){
    7. delete ui->Monitor_tree->takeTopLevelItem(i);
    8. }
    9. for( int i=0 ; i<count ; ++i ){
    10. item->setText(0,arrVisDetails .at(i));
    11. ui->Monitor_tree->addTopLevelItem(item);
    12. }
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    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.

  6. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #6
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QTreewidget clear creates memory leaks

    Thamsks,
    I will try it

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreewidget clear creates memory leaks

    clear() deletes all the items in the widget, there is no leak here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QT Memory Leaks
    By lukabratzi in forum Qt Programming
    Replies: 17
    Last Post: 28th February 2012, 20:01
  2. Memory Leaks
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2008, 16:26
  3. Memory leaks..
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2008, 19:28
  4. memory leaks
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2008, 08:00
  5. why there are memory leaks in Qt?
    By cocalele in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2006, 09:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.