Mark
Mark

Reputation: 6341

How do you get a responsive GUI if your codebehind is running an infinte loop? PyQT

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?

Upvotes: 4

Views: 2195

Answers (2)

user195488
user195488

Reputation:

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

Upvotes: 4

user44484
user44484

Reputation:

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.

Upvotes: 0

Related Questions