views:

182

answers:

2

If you have a function consistently running an infinite loop in the background, how will your GUI ever be responsive? It is waiting for the loop to finish and this renders the interface useless. How is this solved in PyQT?

+3  A: 

Use threads.

In Qt, they use something called Signals and Slots. I haven't used Qt since college, but there are plenty of good resources here:

PyQt Wiki: Threading,_Signals_and_Slots

See also this related SO post: Threading in a PyQt application: Use Qt threads or Python threads? or

Python - PyQt app in seperate thread

0A0D
A: 

You would run the non-GUI code in a QThread. Then your GUI will remain responsive.

For a tutorial on threading in QT, see this link:

http://doc.trolltech.com/4.4/threads.html

The documentation for Qt's threading class (QThread) is available at this link:

http://doc.trolltech.com/4.4/qthread.html#details

They are both references to the C++ documentation, but are still both valuable even when using PyQt, especially where the PyQt documentation is not as robust.

Chris Cameron
I meant to supply the second link ("this doc") as the original link, but decided that they would together be a good start for learning QThread. I'll edit the response to be more coherent
Chris Cameron