Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. app using "excessive" CPU
Qt 6.12 LTS is out! See what's new in the release blog

app using "excessive" CPU

Scheduled Pinned Locked Moved Solved General and Desktop
42 Posts 10 Posters 20.9k Views 4 Watching
  • 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.
  • JonBJ JonB

    @mzimmers
    Try not running your application, or switch the machine off ;-)

    Given that this is running on Windows, I can't use the profiler built into Creator

    Does your MSVC/MinGW compiler come with a usable profiler, nothing to do with Qt?

    In your paintEvent() override @mrjj had in mind for you to try a debugger breakpoint there and look at the stack trace. You will doubtless need to perhaps put a delay/count on the breakpoint, or set it while the app is in the middle of running. I don't actually know whether paint events will show anything interesting on the stack.

    You can use the top-level eventFilter() to examine most of what's going on, if you have to :( Debug every event's type to file/debug output window for a couple of seconds into your "idle". Search the output, you're probably interested in what you see just before the updating starts, or as it goes along.

    mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #16

    @JonB using MinGW, and I don't think it has a profiler. I could look at 3rd party products, but it's probably easier just to have a co-worker build this on Linux, and then run the profiler. (Hopefully the problem will occur on Linux!)

    Here's the stack trace you mentioned:
    stack.PNG
    Maybe you can see something useful in it; I can't.

    JonBJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @JonB using MinGW, and I don't think it has a profiler. I could look at 3rd party products, but it's probably easier just to have a co-worker build this on Linux, and then run the profiler. (Hopefully the problem will occur on Linux!)

      Here's the stack trace you mentioned:
      stack.PNG
      Maybe you can see something useful in it; I can't.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #17

      @mzimmers
      An expert may have something to say about the traceback. All I know is it would be nice to know which the QWidget is. Wait, this code is yours for Widget? So which of your widgets is it? If you break more than once, is it always the same widget?

      I can see QCoreApplication::sendSpontaneousEvent(). You sure you're not "wiggling"? :)

      (Hopefully the problem will occur on Linux!)

      Nope... ;-)

      mzimmersM 1 Reply Last reply
      0
      • JonBJ JonB

        @mzimmers
        An expert may have something to say about the traceback. All I know is it would be nice to know which the QWidget is. Wait, this code is yours for Widget? So which of your widgets is it? If you break more than once, is it always the same widget?

        I can see QCoreApplication::sendSpontaneousEvent(). You sure you're not "wiggling"? :)

        (Hopefully the problem will occur on Linux!)

        Nope... ;-)

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #18

        @JonB yes Widget is my oh-so-creative name for my main QWidget class, which is the only QWidget the app uses (unless you push one of the buttons). So yeah, it's always the same Widget.

        Someone else mentioned wiggling, but I'm not sure I know what it means. The problem occurs even when the app loses focus, though.

        And, if you're confident this won't happen on Linux, then maybe the problem isn't in my code space...

        JonBJ mrjjM 2 Replies Last reply
        0
        • mzimmersM mzimmers

          @JonB yes Widget is my oh-so-creative name for my main QWidget class, which is the only QWidget the app uses (unless you push one of the buttons). So yeah, it's always the same Widget.

          Someone else mentioned wiggling, but I'm not sure I know what it means. The problem occurs even when the app loses focus, though.

          And, if you're confident this won't happen on Linux, then maybe the problem isn't in my code space...

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #19

          @mzimmers said in app using "excessive" CPU:

          And, if you're confident this won't happen on Linux, then maybe the problem isn't in my code space...

          Noooo, I put a wink --> ;-) <--
          I absolutely do not know whether it will repro under Linux, if you're lucky it will, I just meant sod's law it won't!

          1 Reply Last reply
          0
          • mzimmersM mzimmers

            @JonB yes Widget is my oh-so-creative name for my main QWidget class, which is the only QWidget the app uses (unless you push one of the buttons). So yeah, it's always the same Widget.

            Someone else mentioned wiggling, but I'm not sure I know what it means. The problem occurs even when the app loses focus, though.

            And, if you're confident this won't happen on Linux, then maybe the problem isn't in my code space...

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

            @mzimmers
            Hi
            That stack trace is for

            1. starting app
              2: add break point
              3: let it loose focus to see the issue

            and not just set at startup so we ssee the first paint when it becomes visible?
            Just asking to be sure. Not seeing anything special besides maybe the sendSpontaneousEvent

            mzimmersM 1 Reply Last reply
            0
            • mrjjM mrjj

              @mzimmers
              Hi
              That stack trace is for

              1. starting app
                2: add break point
                3: let it loose focus to see the issue

              and not just set at startup so we ssee the first paint when it becomes visible?
              Just asking to be sure. Not seeing anything special besides maybe the sendSpontaneousEvent

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #21

              @mrjj I'm not sure I follow you, but I modified my routine:

              void Widget::paintEvent(QPaintEvent *event)
              {
                  static int count = 0;
                  if (event->spontaneous())
                  {
                      //qDebug() << "spontaneous event" << count++;
                  }
                  else
                  {
                      QWidget::paintEvent(event);
                  }
              }
              

              I put a breakpoint on QWidget::paintEvent...and it never, EVER hits. (Also, with this change, CPU usage remains the same.)

              This just gets weirder and weirder.

              mrjjM 1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #22

                I am sorry this is such a struggle. I don't have anything more to add except a sarcastic example of wiggling:
                https://media.giphy.com/media/xT9KVjBI3W2283URdm/source.mp4

                C++ is a perfectly valid school of magic.

                mrjjM 1 Reply Last reply
                0
                • fcarneyF fcarney

                  I am sorry this is such a struggle. I don't have anything more to add except a sarcastic example of wiggling:
                  https://media.giphy.com/media/xT9KVjBI3W2283URdm/source.mp4

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

                  @fcarney
                  hehe that the sorts you want to debug with a flame thrower...

                  1 Reply Last reply
                  1
                  • mzimmersM mzimmers

                    @mrjj I'm not sure I follow you, but I modified my routine:

                    void Widget::paintEvent(QPaintEvent *event)
                    {
                        static int count = 0;
                        if (event->spontaneous())
                        {
                            //qDebug() << "spontaneous event" << count++;
                        }
                        else
                        {
                            QWidget::paintEvent(event);
                        }
                    }
                    

                    I put a breakpoint on QWidget::paintEvent...and it never, EVER hits. (Also, with this change, CPU usage remains the same.)

                    This just gets weirder and weirder.

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

                    @mzimmers

                    well i just asked if it was not as in first run stack trace.
                    but i think you are doing as i think reading your last post.

                    Its very odd. Indeed.
                    Does
                    //qDebug() << "spontaneous event" << count++;
                    trigger alow when testing then ?

                    mzimmersM 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @mzimmers

                      well i just asked if it was not as in first run stack trace.
                      but i think you are doing as i think reading your last post.

                      Its very odd. Indeed.
                      Does
                      //qDebug() << "spontaneous event" << count++;
                      trigger alow when testing then ?

                      mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #25

                      @mrjj I just realized something -- from the docs:

                      bool QEvent::spontaneous() const
                      Returns true if the event originated outside the application (a system event); otherwise returns false.
                      
                      The return value of this function is not defined for paint events.
                      

                      So, I think this exercise was a waste of time.

                      mrjjM 1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        @mrjj I just realized something -- from the docs:

                        bool QEvent::spontaneous() const
                        Returns true if the event originated outside the application (a system event); otherwise returns false.
                        
                        The return value of this function is not defined for paint events.
                        

                        So, I think this exercise was a waste of time.

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

                        @mzimmers

                        Well i find it very odd you see many paint events for the widget (with event filter) but
                        its not constantly Hitting the break point in paintEvent. ??
                        Or did i misunderstood something ?

                        mzimmersM 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @mzimmers

                          Well i find it very odd you see many paint events for the widget (with event filter) but
                          its not constantly Hitting the break point in paintEvent. ??
                          Or did i misunderstood something ?

                          mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #27

                          @mrjj you understand it perfectly, and "odd" is a mild term for it.

                          I seriously don't know what to look at here. I'm afraid that the profiler we run tomorrow won't show anything in my code space.

                          mrjjM JonBJ 2 Replies Last reply
                          0
                          • mzimmersM mzimmers

                            @mrjj you understand it perfectly, and "odd" is a mild term for it.

                            I seriously don't know what to look at here. I'm afraid that the profiler we run tomorrow won't show anything in my code space.

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

                            @mzimmers
                            Do you have any timers or threads ?
                            Something scanning for those devices you show ?

                            Also, just for test. a plain normal GUI project with say a ListWidget on it does not show this
                            cpu usage, right?

                            It must somehow be related to your code ?

                            1 Reply Last reply
                            0
                            • mzimmersM mzimmers

                              @mrjj you understand it perfectly, and "odd" is a mild term for it.

                              I seriously don't know what to look at here. I'm afraid that the profiler we run tomorrow won't show anything in my code space.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #29

                              @mzimmers said in app using "excessive" CPU:

                              I'm afraid that the profiler we run tomorrow won't show anything in my code space.

                              Always with the negative waves https://www.youtube.com/watch?v=KuStsFW4EmQ Have a little faith, baby!

                              1 Reply Last reply
                              1
                              • mzimmersM Offline
                                mzimmersM Offline
                                mzimmers
                                wrote on last edited by
                                #30

                                Well, my associate hasn't yet built the app on Linux, but I discovered the source (if not the cause) of the problem: my logo.

                                I have a small (201x59 pixel) PNG in the upper left of my widget. When I remove it from my .qrc file, the CPU usage disappears.

                                Any ideas on this one?

                                1 Reply Last reply
                                0
                                • fcarneyF Offline
                                  fcarneyF Offline
                                  fcarney
                                  wrote on last edited by
                                  #31

                                  @mzimmers said in app using "excessive" CPU:

                                  my logo

                                  Wow! That is all I can say.
                                  🍿

                                  C++ is a perfectly valid school of magic.

                                  1 Reply Last reply
                                  0
                                  • mzimmersM Offline
                                    mzimmersM Offline
                                    mzimmers
                                    wrote on last edited by
                                    #32

                                    I suspect it has something to do with this line:

                                    painter.drawPixmap(rect(), pixmap()->scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
                                    

                                    I don't need to scale it; what do I replace the call to scaled() with?

                                    mrjjM J.HilkJ 2 Replies Last reply
                                    0
                                    • mzimmersM mzimmers

                                      I suspect it has something to do with this line:

                                      painter.drawPixmap(rect(), pixmap()->scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
                                      

                                      I don't need to scale it; what do I replace the call to scaled() with?

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

                                      @mzimmers said in app using "excessive" CPU:

                                      painter.drawPixmap(rect(), pixmap()->scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));

                                      painter.drawPixmap(rect(), pixmap());
                                      actaully scale it to rect so @Bonnie version is correct.
                                      

                                      to draw it at original size.

                                      or you can simply scale it once outside paintEvent and reuse the scaled version.

                                      1 Reply Last reply
                                      1
                                      • B Offline
                                        B Offline
                                        Bonnie
                                        wrote on last edited by Bonnie
                                        #34

                                        To not scale at all, should not use a rect as parameter (unless the rect size is the same as the pixmap size).

                                        painter.drawPixmap(0, 0, pixmap());
                                        

                                        (0, 0) is the draw position.

                                        1 Reply Last reply
                                        1
                                        • mzimmersM mzimmers

                                          I suspect it has something to do with this line:

                                          painter.drawPixmap(rect(), pixmap()->scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
                                          

                                          I don't need to scale it; what do I replace the call to scaled() with?

                                          J.HilkJ Offline
                                          J.HilkJ Offline
                                          J.Hilk
                                          Moderators
                                          wrote on last edited by
                                          #35

                                          @mzimmers great you found it! But paintEvent itself should not be called that much regularly! I suspect your logo is being resized (wiggles) all the time!


                                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                          Q: What's that?
                                          A: It's blue light.
                                          Q: What does it do?
                                          A: It turns blue.

                                          1 Reply Last reply
                                          2

                                          • Login

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