Wednesday, February 20, 2008

Problem with Threads in GUI

When trying to implement a GUI, I tried to create a new thread on pressing
the "execute" button, However, I got the following errors:
Xlib: unexpected async reply (sequence 0x4fc8)!

The problem turned out to be that I update the GUI from within my callback thread. In practice, no thread other than the main thread (aka "GUI-thread") may update any widget (that is, no call to QWidget::update(), QWidget::setFoo() etc. from another thread).

What can I do to solve the problem? I can try the following:
In my worker thread put events into the Qt event queue and inform the GUI thread that it needs to update its GUI state according to the "model" (that is, your sound data).

See QApplication::postEvent. This is a common mistake, see also Qt archive for more details. Maybe qtforum.org knows more as well (haven't checked).

No comments: