tags:

views:

31

answers:

1

I am trying to add QProgressBar in my code but having some troubles. I added progress bar via Designer and in the code, I pass the pointer to QprogressBar object to a separate thread to have it update QProgressBar as it's processing data, however, I get this message: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy->request)) >= 0)' failed. I am running Qt-4.5.0 on Ubuntu 8.10(2.6.27-11). I also tried Qt-4.3.5 in RHEL5(2.6.18) and I get different error, something cryptic like X error with QPaint error. It's seems to be fine when I updates progress bar from my main app exec loop.

Please help Nimesh

+3  A: 

The QWidget class and all of its subclasses, including QProgressBar, are not reentrant and can not be used outside of the main thread. Refer to the following documentation:

http://doc.trolltech.com/4.5/threads.html#threads-and-qobjects

You are getting errors because you are trying to update the QProgressBar from outside of the main thread.

The preferred way of updating the progress bar is to make an object affiliated with your data processing thread emit a signal periodically as it progresses, then connect this signal to the setValue(int) slot in QProgressBar. Qt will ensure that the signal-slot connection is thread-safe. Refer to the documentation on connecting signals and slots across threads:

http://doc.trolltech.com/4.5/threads.html#signals-and-slots-across-threads

Hope this helps.

RA