Right way to avoid 100% cpu on main thread

  • 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,

  • Qt Champions 2018

    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?

Log in to reply

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