How to access Qt components loaded from file?

Michael Torrie torriem at
Thu Nov 20 16:37:15 CET 2014

On 11/19/2014 07:53 PM, Juan Christian wrote:
> Thanks, it's working using QTimer. The thing is that whenever the program
> is going to do something, in my case, draw a new QGroupBox with some
> components inside and put it in the Form (I'm using VBoxLayout in the main
> form) the program freezes, and I'm using very simple components just for
> testing.This shouldn't be normal, right?
> Am I doing something wrong?

Make sure your callbacks always return very quickly.  Never do any long
task in a GUI event callback.  Even your timer event callbacks should
return quickly.  If you need to do something that takes longer, like
load a web page from a url, you need to either do it asynchronously with
Qt's API, or spawn a thread to do the heavy lifting.  Qt provides a
whole bunch of apis for doing this (that overlap python's standard
library.  For example, instead of urllib2, there's QNetwork
( that provides an
asynchronous means of doing sockets, retrieving web content, etc.  They
aren't very pythonic probably, but they do all emit signals upon
completion, so yo don't have to sit in a callback waiting for the
download to complete.

If you do want to spawn a thread to handle your longer-running task
(normal urllib2), you'll have to come up with a way of notifying the
main thread that the download is complete; you shouldn't call any GUI
calls from the thread, typically.  Here's an example of how to have a
thread notify the main loop of completion:

A quick google can reveal all this information, but it's harder if you
don't know what to look for.  So I hope this helps.

More information about the Python-list mailing list