Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-92272

Windows: memory leak with QPainter/QPrinter (PDF Creator 1.7.2)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Out of scope
    • Affects Version/s: 5.12.2, 5.15.0
    • Fix Version/s: None
    • Component/s: GUI: Printing
    • Labels:
      None
    • Environment:
      visual studio 2017
    • Platform/s:
      Windows

      Description

      I have a memory leak problem while simply using QPrinter/QPainter in my C++/QT application, to print several pictures to a printer (physical or "print to pdf" printer).

      Each time the memory used raise up to about 200/500 Mo each time(depend of number of pictures choosen) with a little test project and *doesnt'n bring back* after print task and coming back to main event loop. 

      I ever tried some modifications such as put QPrinter and QPainter variable in member of wind object, try in debug mode with VS, or release without it... but it's the same.

      Here a code test to illustrate this problem:

       

      ```c++
      wind::wind(QWidget *parent) : QWidget(parent) {
       _printOut = new QPushButton("Print");
       connect(_printOut, &QPushButton::clicked, this, &wind::printOut);
       QGridLayout *lay = new QGridLayout();
       lay->addWidget(_printOut);
       _photoPrinterComboBox = new QComboBox(); QStringList printList = QPrinterInfo::availablePrinterNames();
      _photoPrinterComboBox->addItems(printList);
      _photoPrinterComboBox->setMaximumWidth(250);
      _photoPrinterComboBox->setCurrentIndex(0);
       
      lay->addWidget(_photoPrinterComboBox); 
      setLayout(lay);
      show();
      }
      void wind::printOut(){
       QPrinterInfo printerInfo = QPrinterInfo::printerInfo(_photoPrinterComboBox->currentText());
      QPrinter printer(printerInfo, QPrinter::HighResolution); 
      QStringList files = QFileDialog::getOpenFileNames(this, "choisir images", "", "*.jpg", 0);
      QPainter paint;
      QPixmap img;
      
      for (int i(0); i < files.size(); i++) {
      
      
      bool succ = img.load(files.at(i));
      if (succ) { 
      QFileInfo fi(files.at(i)); 
      paint.begin(&printer); 
      qreal dpiX = printer.physicalDpiX(); 
      qreal dpiY = printer.physicalDpiY();
       
      paint.setRenderHint(QPainter::Antialiasing, true);
      QTransform trMillimeters = QTransform::fromScale(dpiX / 25.400, dpiY / 25.400); paint.setWorldTransform(trMillimeters, false);
      paint.drawPixmap(img.rect(), img); // the problem seem to appear here
      paint.end(); 
      }
      }
       
      
      }```
      
      

       main.cpp:

       

       

      #include "wind.h"#include "wind.h"#include <QtWidgets/QApplication>
      int main(int argc, char *argv[]){ QApplication app(argc, argv); QMainWindow *mw = new QMainWindow(); QCoreApplication::setOrganizationName("QtExamples");
       QMainWindow *mainW = new QMainWindow(); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); wind *w = new wind(); mainW->takeCentralWidget(); mainW->setCentralWidget(w); mainW->show();
       return app.exec();}
      

       

      My forum topic here

        Attachments

        1. Capture d’écran 2021-03-30 173806.png
          Capture d’écran 2021-03-30 173806.png
          33 kB
        2. QPainterTest.zip
          2 kB
        3. qtbug92272_diag.diff
          1 kB
        4. qtbug92272.zip
          10 kB
        5. testPainter.zip
          4.74 MB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            johnlayt John Layt
            Reporter:
            labrass alexandre brassard
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes