Common main loop: Qt ported to glib main loop (experimental)
nf2 at scheinwelt.at
Thu Nov 25 00:26:42 EET 2004
I tried to explore the common main loop issue a little more: How could a
"select" based main loop like Qt be ported to a poll style system with a
generic "prepare/check/dispatch" scheme like glib?
According to previous discussions it seems that the glib main loop has a
quite good and generic concept. If we take the glib concept as prototype
for an "universal" event loop, "redesigning" Qt to run on top of glib is
an interesting experiment.
The problem: The Qt eventloop is written closely around the select
function, lots of "fd_sets" and FD_SET, FD_ZERO,... macros are spread
over the eventloop and socket-notifier code. The Qt-Documentation says
that QEventLoop can be subclassed to run with other main-loops, but i
doubt that it will run on top of another main loop like as a glib
GSource. (And I also doubt that QtGtk really works.)
Cause i'm lazy, i thought the easiest way to do a port is to write a
"select->poll->glib/GSource" translation/wrapper library and to patch Qt
to run with this wrapper. A prototype of this library called
"FKSEL" (Fake select) can be downloaded here:
The functions in fksel_wrapper.h synchronize "select" style fd_sets with
a hidden GSource using g_source_add_poll() and g_source_remove_poll().
Additionally, the FkselWrapper struct provides a way to plug custom
prepare/check/dispatch funcs. The GSource is hidden, because i have the
impression that direct linking to glib is harder to get politically
Sample fksel functions: Synchronizing fd_sets with a Gsource:
FkselWrapper * wrapper,
FkselWrapper * wrapper,
You can look at the fksel_wrapper_test.c demo to see how things work.
Hacking Qt - What I did:
I split the QEventLoop::processEvents( ProcessEventsFlags flags ) method
into separate prepare/check/dispatch functions to run with the
fksel_wrapper and to replace all the FD_SET, FD_CLR,... macros with the
A patch for Qt-x11-free-3.3.3 is attached to this mail.
My Qt patch and FKSEL are still VERY ugly, but the Qt-examples which
come with Qt seem to work quite well. Maybe good enough for a "proof of
All you have to do is to
* install fksel
* apply the patch to Qt and
* ./configure Qt with the -lfksel flag.
(also look at the Qt compilation guide:
Support and Comments from the main-loop experts would be very cool! Open
questions: threading, mutexes, using gtk and qt in-process...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 17444 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xdg/attachments/20041124/9b05c12a/attachment.bin
More information about the xdg