[Interest] Qt 5.9 built with Glib support under macOS - event loop doesn't work

Thiago Macieira thiago.macieira at intel.com
Wed Oct 11 21:13:45 CEST 2017

On quarta-feira, 11 de outubro de 2017 00:30:51 PDT Melanie Cappelaere wrote:
> I'm having the same problem with a Qt 5.9 which was built with the -glib
> option, except that it also doesn't work with a QCoreApplication. A quick
> look at the code of QCoreApplicationPrivate::createEventDispatcher makes me
> suspect this changed in between Qt 5.5 and Qt 5.6 (commit
> 97c8f6aa9c774aa0aac8948dd619e93944ec104a, if I'm not mistaken).
> My tests indicate that neither the QCocoaEventDispatcher nor the
> QEventDispatcherUNIX handle the glib events. An experimental hack to use
> QEventDispatcherGlib in QCoreApplication does work, which matches the
> observations for Qt 5.2.

Correct. The Glib dispatcher is not expected to work on a Mac or Windows. If 
you need that, please use GMainLoop yourself in a separate thread.

> On the Gui side, I have the impression that it was dropped or got lost
> during the major reworks for Qt 5. I haven't been able to find out if this
> was intentional or accidental.

The GUI event loop has never supported Glib events on a Mac or on Windows. The 
change you pointed to makes that true now also for non-GUI. That change is 
pointing towards future goals of making the CFRunLoop run on all threads: 
we've been having problems with certain Apple API (like Bluetooth) not working 
outside the GUI thread.

> So I'm wondering if the glib event loop is supported for Qt5 on macOS, and
> if so, how do I enable support for it?

It's not. I don't think we'll accept patches for it either, so your options 
are to either patch Qt or to run drive the GMainLoop yourself.

A third alternative is to change Glib so that it integrates with the CFRunLoop 
instead of driving things on its own. Then when Qt runs that (you have to set 
QT_EVENT_DISPATCHER_CORE_FOUNDATION to 1), Glib events get dispatched too.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list