Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102161

EventLoops can get stuck on Mac (quit call to eventloop fails)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.2.3, 6.3
    • Core: Event loop
    • None
    • macOS

    Description

      See attached example. We start a dialog and while it is running two other event loops are started. Each of these should be finished about 1.5s after being started. We quit the application after 20 seconds. The behavior is as expected on Windows, but on Mac an event loop gets stuck and it does not exit before the application is quit. (Can also be triggered by closing both windows).

      Example output:
      1.553 start loop: QEventLoop(0x7ffeefbfbf00)
      2.652 start loop: QEventLoop(0x7ffeefbfa1e0)
      3.130 timeout; loop: QEventLoop(0x7ffeefbfbf00)
      4.228 timeout; loop: QEventLoop(0x7ffeefbfa1e0)
      4.229 finished loop: QEventLoop(0x7ffeefbfa1e0)
      20.268 finished loop: QEventLoop(0x7ffeefbfbf00)

      It can be seen that the timeout works fine, but one of the eventloop fails to quit (0x7ffeefbfbf00).

      An improvement (if not a complete solution) could be to do the following in
      bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
      (patch made for 5.15.2)

      --- qt-everywhere-src-5.15.2/qtbase/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm.orig	2022-01-17 11:33:08.000000000 +0100
      +++ qt-everywhere-src-5.15.2/qtbase/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm	2022-01-17 13:49:25.000000000 +0100
      @@ -409,6 +409,8 @@
                       QBoolBlocker execGuard(d->currentExecIsNSAppRun, false);
                       while ([NSApp runModalSession:session] == NSModalResponseContinue && !d->interrupt) {
                           qt_mac_waitForMoreEvents(NSModalPanelRunLoopMode);
      +                    if (d->interrupt)
      +                      d->propagateInterrupt = true;
                           if (session != d->currentModalSessionCached) {
                               // It's possible to release the current modal session
                               // while we are in this loop, for example, by closing all
      

      Attachments

        1. EventloopIssue.pro
          0.5 kB
        2. main.cpp
          1 kB

        Issue Links

          Activity

            People

              vestbo Tor Arne Vestbø
              tmartsum Thorbjørn Lund Martsum
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: