QProgressBar Error

风格不统一 提交于 2019-12-25 01:38:17

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2184400/qprogressbar-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!