Important: Please read the Qt Code of Conduct -

High CPU usage when saving QList<QPixmap>

  • Hi!
    I have a QList<QPixmap> I want to save to a series of files. Actually the simplified code below saves them fine. But during the operation my CPU usage goes crazy. Is there a basic trick to decrease CPU usage in such a case?

    Here's an example code like I'm using. It's pretty straightforward:

    QList<QPixmap> allPixmaps;
    // Populate allPixmaps here
    for(int i = 0; i < allPixmaps.count(); i++) {
        QPixmap pixmap =;
        // Calculate fileName;
    // Zip the saved pixmaps here

    As I said, it's pretty straightforward. The problem is during this for loop, CPU usage goes crazy. Especially if I have a long list of pixmaps and/or with high resolutions. I'm sure I lack some basic knowledge, but how can I avoid this?

    Edit: I tried using pointers for pixmaps and deleting them after saving, but that didn't work.

    Edit: Do you think using QTimers would work?

    Edit:: BTW, if it makes a difference, I'm using Qt 5.4.2 on Ubuntu 15.10

  • Lifetime Qt Champion

    Try (use reference):

    QPixmap &pixmap = allPixmaps[i];

    Else each pixmap is copied in the loop.

  • @jsulm Thank you very much for the answer.

    Unfortunately, it didn't work either.

  • Lifetime Qt Champion

    It is the actual saving to disk that takes I assume since you mention no image processing
    is happening.
    so only cure is not to save all of them in one go.

    How many images is there ?

  • @mrjj Thanks for the answer.

    It varies, because it's an animation program, and user creates or imports the pixmaps.

    Edit: This is for saving an animation document. I save all the frames as png files, and zip them with some xml data.

    Do you think if I save the files directly in the zip file, the problem would be solved?

  • Lifetime Qt Champion

    well it does take time to save big image to file.
    so not sure there is easy cure for that.

    Why does it matter that it uses lots of cpu to save?

  • @mrjj Thanks.

    It might not be a critical problem of course. But I worry that some users might have issues. Do you think it's not that important?

  • Lifetime Qt Champion

    well if takes many minutes it's a problem.
    but for 10 secs it would be fine.
    Animation is often heavy
    so those user often do have good machines.
    and you could popup a dialog with
    "save in progress, might take some time"
    so they know its working.

  • @mrjj Thanks.

    On some machines it might take some minutes.

    I will put a progress bar for saving operations, and I think best way to deal with this is, warning users against using too long animations with high resolutions at once.

    Thanks, I will mark this as solved.

  • Lifetime Qt Champion

    I agree. Since it will really depends on user machines.
    I use ramdisk for saving so it is very fast, where old
    hd will take a long time.
    Besides I user makes full HD animation with 1000 frames,
    I assume he do know it is a bit heavy :)

Log in to reply