Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. High CPU usage when saving QList<QPixmap>
QtWS25 Last Chance

High CPU usage when saving QList<QPixmap>

Scheduled Pinned Locked Moved Solved General and Desktop
qpixmap
10 Posts 3 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iamqt
    wrote on last edited by iamqt
    #1

    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

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Try (use reference):

      QPixmap &pixmap = allPixmaps[i];
      

      Else each pixmap is copied in the loop.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      1
      • jsulmJ jsulm

        Try (use reference):

        QPixmap &pixmap = allPixmaps[i];
        

        Else each pixmap is copied in the loop.

        I Offline
        I Offline
        iamqt
        wrote on last edited by
        #3

        @jsulm Thank you very much for the answer.

        Unfortunately, it didn't work either.

        mrjjM 1 Reply Last reply
        0
        • I iamqt

          @jsulm Thank you very much for the answer.

          Unfortunately, it didn't work either.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          I 1 Reply Last reply
          1
          • mrjjM mrjj

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

            I Offline
            I Offline
            iamqt
            wrote on last edited by iamqt
            #5

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

            mrjjM 1 Reply Last reply
            0
            • I iamqt

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              I 1 Reply Last reply
              1
              • mrjjM mrjj

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

                I Offline
                I Offline
                iamqt
                wrote on last edited by
                #7

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

                mrjjM 1 Reply Last reply
                0
                • I iamqt

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  I 1 Reply Last reply
                  1
                  • mrjjM mrjj

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

                    I Offline
                    I Offline
                    iamqt
                    wrote on last edited by
                    #9

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

                    mrjjM 1 Reply Last reply
                    0
                    • I iamqt

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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 :)

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved