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. Right way to avoid 100% cpu on main thread
Forum Updated to NodeBB v4.3 + New Features

Right way to avoid 100% cpu on main thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 829 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.
  • T Offline
    T Offline
    trikko
    wrote on last edited by
    #1

    On main thread there a loop waiting for different things to happen.
    If i do this:

    while(...) { qApp->processEvents(); } gui responds but cpu is stucked to 100%

    If i do this:

    while(..) { qApp->processEvents(); QThread::sleep(0); } gui responds but cpu is stucked to 25%.

    Which is the right way to get a low cpu usage in an empty loop keeping app responsive?

    Thanks in advance,
    A.

    aha_1980A 1 Reply Last reply
    0
    • T trikko

      On main thread there a loop waiting for different things to happen.
      If i do this:

      while(...) { qApp->processEvents(); } gui responds but cpu is stucked to 100%

      If i do this:

      while(..) { qApp->processEvents(); QThread::sleep(0); } gui responds but cpu is stucked to 25%.

      Which is the right way to get a low cpu usage in an empty loop keeping app responsive?

      Thanks in advance,
      A.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi @trikko

      the correct way is to react to a signal in a slot instead of using wait loops (at least in main thread).

      what exactly are you waiting for?

      Qt has to stay free or it will die.

      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 Extensions
      • Unsolved