Modal dialog blocks event loop on Mac OS

  • I have such behaviour in the app

    @QTimer timer;
    timer.connect( &timer, &QTimer::timeout, DO_SOMETHIG );
    timer.start( 0 );@

    then in somewhere:

    @QMessageBox dlg( ... );

    and after that the event loop freezes, until some event will be passed to the dlg. For example the mouse cursor hover the dialog window. Only in this case the app's event loop will thaw and DO_SOMETHIG from the above timer will be executed.

    This behaviour reproduced on MacOS. On Linux the event loop not freezes, DO_SOMETHIG executes as expected. On Windows this issue was not tested.

    In the search for solutions I found "this": post. Here was told that modal dialogs uses special optimizations for mac that holds in file I researched this file and came to the conclusion that

    modal dialogs on Mac stops the execution of qt's event loop and transfers control to the NSApp while dialog executes. Only window's events from cocoa can awake qt's event loop.

    Am i right?

  • Lifetime Qt Champion


    Haven't checked yet but you use case can probably be solved by using QDialog's open function rather than exec

    Hope it helps

  • Unfortunately, I need to use exec(), because want to get feedback from user before continue execution. For example QMessageBox::Question.

  • To get the feedback from the dialog connect to its signals and "continue execution" there. You can connect a c++ closure if you want to stay in the same method.

    This is how it works.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.