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. QEventLoop and QCoreApplication::processEvents
QtWS25 Last Chance

QEventLoop and QCoreApplication::processEvents

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 19.0k 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    is there i difference between:

    QEventLoop loop;
    loop.exec();
    

    and

    while (true)  {
       QCoreApplication::processEvents();
    }
    

    Thanks!

    kshegunovK 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Well QEventLoop is a local event loop so
      there exists 2 at that moment in time while
      "processEvents" just drives the default one.

      Its best if you can design your application so no local waiting is needed. :)

      1 Reply Last reply
      1
      • beeckscheB beecksche

        Hi,
        is there i difference between:

        QEventLoop loop;
        loop.exec();
        

        and

        while (true)  {
           QCoreApplication::processEvents();
        }
        

        Thanks!

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @beecksche said in QEventLoop and QCoreApplication::processEvents:

        is there i difference

        Yes, a huge difference. For one QEventLoop::exec is a "blocking" call, which means it will stop at that position and sleep until there are events to process. Finally if there's a call to QEventLoop::quit (through a signal-slot connection) it will return control to the user code.

        On the other hand QCoreApplication::processEvents() will process as many events there are in the event loop at the time of call and return control to the user code immediately (on first possible occasion).

        @mrjj said in QEventLoop and QCoreApplication::processEvents:

        Well QEventLoop is a local event loop

        Eh, mostly yes. The distinction is made by a single integer that counts the "nest level" of event loops. And as recently discussed in another thread the "local" event loop will spin the global one too. Actually, beside some tweaks like the QCoreApplication::aboutToQuit signal, QCoreApplication::exec just calls QEventLoop::exec.

        Read and abide by the Qt Code of Conduct

        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