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
Forum Updated to NodeBB v4.3 + New Features

QEventLoop and QCoreApplication::processEvents

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 19.1k Views 3 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.
  • B Offline
    B Offline
    beecksche
    wrote on 29 Dec 2016, 09:20 last edited by
    #1

    Hi,
    is there i difference between:

    QEventLoop loop;
    loop.exec();
    

    and

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

    Thanks!

    K 1 Reply Last reply 29 Dec 2016, 21:51
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Dec 2016, 10:06 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
      • B beecksche
        29 Dec 2016, 09:20

        Hi,
        is there i difference between:

        QEventLoop loop;
        loop.exec();
        

        and

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

        Thanks!

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 29 Dec 2016, 21:51 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

        3/3

        29 Dec 2016, 21:51

        • Login

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