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 = allPixmaps.at(i);
        // Calculate fileName
        pixmap.save(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


  • Moderators

    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.


  • Qt Champions 2016

    @iamqt
    Hi
    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?


  • Qt Champions 2016

    @iamqt
    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?


  • Qt Champions 2016

    @iamqt
    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.


  • Qt Champions 2016

    @iamqt
    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
 

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