PyQt4 中保持线程活动
我有一个 PyQt4 应用程序,它在某些时候使用 tarfile 模块打包一个大文件。由于 tarfile 模块没有实现任何回调策略,因此它会阻塞并且 Qt GUI 变得无响应。
我希望 GUI 在此期间不断更新。唯一的可能性是一个单独的线程。 所以,我启动了一个 QThread。我必须在 QThread 中做什么才能使 GUI 自行更新? 一旦 tar 进程完成,我希望线程完成。
谢谢! 内森
I have a PyQt4 application, which at some point packs a big file using the tarfile module. Since the tarfile module does not implement any callback strategy, it blocks and the Qt GUI gets unresponsive.
I want the GUI to keep updating during that time. The only possibility is a separate thread.
So, I start a QThread. What do I have to do in the QThread to make the GUI update itself?
As soon, as the tar process is finished, I want the thread to finish.
Thanks!
Nathan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QThread 与普通的 Python 线程几乎相同,因此您可以使用普通的通信方法。然而,QThreads 也有一些可用的信号,所以如果您只是连接到这些信号,那么您就完成了。
在你的 GUI 代码中做这样的事情,你就差不多完成了:
还有一个
termerated
和started
信号可供你使用:)QThread's are pretty much identical to normal Python threads so you can just use normal communication methods. However, QThreads also have a few signals available, so if you simply connect to those, than you're done.
In your GUI code do something like this and you're pretty much done:
There is also a
terminated
andstarted
signal available which you can use :)