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. Why this works: QCoreApplication::processEvents()

Why this works: QCoreApplication::processEvents()

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • R Offline
    R Offline
    RobM
    wrote on last edited by RobM
    #1

    Hey guys, so I am trying to figure out why it is that when I use QCoreApplication::processEvents() my program works but if I don't it doesn't work correctly.

    Basically, I have no idea what the problem is. In my c++ code I am sending a signal, then I am processing an event, then I am calling a function, then I am emitting another signal:

          emit reconfiguring(true);
          //QCoreApplication::processEvents();
          changeMountLocation(location);
          emit reconfiguring(false);
    

    based on that signal I am creating a popup in my QML. However, if I don't un-comment the line QCoreApplication::processEvents() then the function is run prior to the popup showing up, and if I do un-comment that line then the popup shows up when it should.

    This means that, for some reason, the UI is waiting on the back end for something.... but what? I am not asking for anything, and I can't think of an easy way to figure out why its hanging...

    any ideas?

    jsulmJ 1 Reply Last reply
    0
    • R RobM

      Hey guys, so I am trying to figure out why it is that when I use QCoreApplication::processEvents() my program works but if I don't it doesn't work correctly.

      Basically, I have no idea what the problem is. In my c++ code I am sending a signal, then I am processing an event, then I am calling a function, then I am emitting another signal:

            emit reconfiguring(true);
            //QCoreApplication::processEvents();
            changeMountLocation(location);
            emit reconfiguring(false);
      

      based on that signal I am creating a popup in my QML. However, if I don't un-comment the line QCoreApplication::processEvents() then the function is run prior to the popup showing up, and if I do un-comment that line then the popup shows up when it should.

      This means that, for some reason, the UI is waiting on the back end for something.... but what? I am not asking for anything, and I can't think of an easy way to figure out why its hanging...

      any ideas?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @RobM said in Why this works: QCoreApplication::processEvents():

      This means that, for some reason, the UI is waiting on the back end for something

      Qt is an event driven framework. That means that there is a event loop which takes next event from the queue each time it is active. The UI will only be updated if the event loop has a chance to handle the events. In you case you emit a signal and call changeMountLocation, so event loop has no chance to run. QCoreApplication::processEvents() lets event loop do its work before you call changeMountLocation.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • R Offline
        R Offline
        RobM
        wrote on last edited by RobM
        #3

        @jsulm So it is possible for an event on the event queue to be popped after the next line of code is being ran? I guess I just assumed it would work sequentially. Is there anyway for me to watch the event queue in real time?

        jsulmJ 1 Reply Last reply
        0
        • R RobM

          @jsulm So it is possible for an event on the event queue to be popped after the next line of code is being ran? I guess I just assumed it would work sequentially. Is there anyway for me to watch the event queue in real time?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @RobM said in Why this works: QCoreApplication::processEvents():

          So it is possible for an event on the event queue to be popped after the next line of code is being ran?

          There is a workaround if you really want to do it sequentially: call https://doc.qt.io/qt-5/qcoreapplication.html#processEvents after emitting the signal.

          https://forum.qt.io/topic/113070/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