Memory usage while printing

  • Hi,

    I develop a drawing sofware, so I would like to print.
    I print tiles wich forms the entire image.
    for each tile of my entire image
    draw piece of image

    I call painter.drawImage it works fine but it use lot of memory.
    If I dont call painter.drawImage and only store QImages i produce,
    I have no "memory leak" so what 's the alternative ?

  • Qt Champions 2017

    What are you asking ?
    If there is another way to draw image?
    painter.drawImage should not cause mem leaks..
    Are you sure its not something else?

  • Sorry for my very bad english.
    I mean if call painter.drawImage in my loop, a lot of memory is used like 2Go for example.

    for(OdInt32 u = 0; u < iHorizontalTileCount; u++)
            OdInt32 printerY = iVStep == 1 ? 0 : uiHeight;
            for(OdInt32 v = 0;  v < iVerticalTileCount; v++)
                OdUInt32 uiCurrentTileWidth = odmin(uiTileWidth, uiWidth - (uiTileWidth * u));
                OdUInt32 uiCurrentTileHeight = odmin(uiTileHeight, uiHeight - (uiTileHeight * v));
                OdInt32 tileX = u * uiTileWidth;
                OdInt32 tileY = v * uiTileHeight;
                OdGsDCRect tileRect(tileX, tileX + uiCurrentTileWidth, tileY, tileY + uiCurrentTileHeight);
                OdGsDCRect snapShotRegion =  regenTile(viewportSize, tileRect);
    //render image
                OdGiRasterImagePtr pImage;
                m_pTeighaPrinter->getSnapShot(pImage, snapShotRegion);
                width = pImage->pixelWidth();
                height = pImage->pixelHeight();
                const OdUInt8* pData = pImage->scanLines();
    // create image
                QImage qtImg((const uchar *) pData, width, height, fmt);
    // paint
                painter.drawImage(iHStep == 1 ? printerX : (printerX - width),
                                   iVStep == 1 ? printerY : (printerY - height),
                                  qtImg,0, 0, width, height);
                printerY += iVStep * height;
                    bRestored = true;
                // progression
                emit sg_progress(iProgress);
            printerX += iHStep * width;

    If I remove line painter.drawImage and store image on list, the memory is not growing.
    I would not pretend that's a memory leak but my problem is like a memory leak.

  • Qt Champions 2017

    You can try to new it so u can delete it after
    drawing. Not sure why painter.drawImage should change anything.

    QImage  *qtImg=new QImage ((const uchar *) pData, width, height, fmt);
                painter.drawImage(iHStep == 1 ? printerX : (printerX - width) xxx
    delete qtImg;

    Also the pData use to create the Image, its deleted else where ? ( or dont need deletion)

  • Lifetime Qt Champion


    How many images are you painting ? Which size are they ?

  • this size is fixed for the printing.
    I make 1000 * 1000 by default
    The number of images depends on the size of paper and the DPI

  • My goal is to be able to print on plotter (sorry google translate)
    Printing on paper with large size (ex 1040mm * 3800mm)

  • Lifetime Qt Champion

    So basically you are drawing several tiles that are about 4MB each ?

  • I made a try:
    store all QImages in list intead of calling drawImage and the memory usage is completely different.

  • Lifetime Qt Champion

    It's not the same use case

  • I compared my code with a MFC code. And the memory usage is totally different.
    I will try another way:
    Is it possible to print with vectorized data, i mean using HPGL to print my plan.
    My goal is to be able to print dwg plan with scale 1:1.


  • Qt Champions 2017

    I would see if you could reuse the dwg reading code from
    That would allow true vector output.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.