Results 1 to 3 of 3

Thread: Report, QTextDocument (memory leak)

  1. #1
    Join Date
    Mar 2012
    Posts
    11
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question Report, QTextDocument (memory leak)

    I have some issues with simple reports that my application makes by QTextDocument, html-page (template), QPrinter and QPrintPreviewDialog. I made classes for this stuff.
    But recently I was realised that I have memory leak. so I tried to find where is it.
    It seems that I found out smth but don't know exactly why this happening..

    I threw out spec. classes and wrote just necessary code:

    Qt Code:
    1. QTextDocument* document;
    2. ........
    3. // in widget's constructor
    4. document = new QTextDocument();
    5. ........
    6. // in widget'd destructor
    7. delete document;
    8. ........
    9.  
    10. //----------------------------------------------------------------------------------------
    11. void fmPartStatInRange::previewSelectionReport() {
    12. QFile file (QCoreApplication::applicationDirPath () + "/reports/statisticPartsInRange.html");
    13. if (!file.open (QIODevice::ReadOnly)) {
    14. QMessageBox::critical (this, "", tr ("Error opening report file %1").arg (file.fileName ()));
    15. return;
    16. }
    17. QTextStream stream (&file);
    18. stream.setCodec (QTextCodec::codecForName ("UTF-8"));
    19. document->clear();
    20. document->setHtml (stream.readAll ());
    21. file.close ();
    22.  
    23. //----------------------------------------------------------------------------------------
    24. void fmPartStatInRange::print(QPrinter *printer) {
    25. #ifdef QT_NO_PRINTER
    26. Q_UNUSED(printer);
    27. #else
    28. document->print(printer);
    29. #endif
    30. }
    31.  
    32. //----------------------------------------------------------------------------------------
    33. void fmPartStatInRange::printReport() {
    34. #ifndef QT_NO_PRINTER
    35. QPrinter printer(QPrinter::HighResolution);
    36. QPrintPreviewDialog preview(&printer, this);
    37. connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*)));
    38. preview.exec();
    39. #endif
    40. }
    41.  
    42. //----------------------------------------------------------------------------------------
    43. void fmPartStatInRange::createReport() {
    44. previewSelectionReport();
    45. if (document)
    46. printReport();
    47. }
    48. //----------------------------------------------------------------------------------------
    To copy to clipboard, switch view to plain text mode 

    I execute createReport() many times and see memory leak.
    But if I comment this line:
    Qt Code:
    1. document->setHtml (stream.readAll ());
    To copy to clipboard, switch view to plain text mode 
    that's all ok. no memory leak.
    of course in this case I don't get any sence of report only white page.

    I use 4.7.3 Qt ver.
    unfortunately I haven't any opportunities to check out it on new Qt ver.

    so what is wrong with this code or maybe it's a bug in Qt lib?

    thanks in advance!
    Last edited by layer; 23rd March 2012 at 04:33.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Report, QTextDocument (memory leak)

    How do you "see memory leak"?

  3. #3
    Join Date
    Mar 2012
    Posts
    11
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Report, QTextDocument (memory leak)

    in win task manager for example.

    here it is 24 Mb in memory before doing smth:
    memory_1.jpg

    after 20 reports (35 Mb):
    memory_2.jpg

    and it's keep growing if we do reports...
    is it normal or I didn't catch smth?

Similar Threads

  1. memory usage report
    By timmu in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2012, 14:42
  2. Qt example with memory leak
    By Squall in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2011, 10:07
  3. Memory leak
    By yxtx1984 in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2010, 11:13
  4. memory leak
    By mattia in forum Newbie
    Replies: 18
    Last Post: 16th January 2008, 10:22
  5. Memory Leak in Qt
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2007, 08:02

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.