Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Solved Why this works: QCoreApplication::processEvents()

    General and Desktop
    2
    4
    350
    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.
    • R
      RobM last edited by 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?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @RobM last edited by

        @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 Reply Quote 2
        • R
          RobM last edited by 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?

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @RobM last edited by

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