简体   繁体   中英

keep alive thread in PyQt4

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM