Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved QEventLoop and QCoreApplication::processEvents

    General and Desktop
    3
    3
    16691
    Loading More Posts
    • 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.
    • beecksche
      beecksche last edited by

      Hi,
      is there i difference between:

      QEventLoop loop;
      loop.exec();
      

      and

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

      Thanks!

      kshegunov 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • kshegunov
          kshegunov Moderators @beecksche last edited by kshegunov

          @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 Reply Quote 1
          • First post
            Last post