PyQt4 中保持线程活动

发布于 2024-09-08 11:58:24 字数 222 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぽ尐不点ル 2024-09-15 11:58:24

QThread 与普通的 Python 线程几乎相同,因此您可以使用普通的通信方法。然而,QThreads 也有一些可用的信号,所以如果您只是连接到这些信号,那么您就完成了。

在你的 GUI 代码中做这样的事情,你就差不多完成了:

thread = Thread()
thread.finished.connect(gui.do_update_thingy)

还有一个 termeratedstarted 信号可供你使用:)

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:

thread = Thread()
thread.finished.connect(gui.do_update_thingy)

There is also a terminated and started signal available which you can use :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文