[PyQt] Question about QTimer and QThreads

Darren Dale darren.dale at cornell.edu
Mon Oct 29 11:31:10 GMT 2007


On Monday 29 October 2007 04:15:45 am Andreas Pakulat wrote:
> On 28.10.07 18:31:25, Darren Dale wrote:
> > I am trying to understand how to run a second event loop using a qthread.
> > The Qt docs indicate this is possible, but I haven't found any examples.
> > I have a simple example that I think should work, but doesn't. When I run
> > my thread's exec_(), it blocks. The actual application I am writing calls
> > the qApp's exec_ before the thread's exec_, but even then the thread's
> > exec_ blocks further execution. Does anyone know how to do this?
>
> Quite easy: Run exec_() inside the new thread, not inside your GUI/main
> thread. To do that add a run() method which only contains
>
> self.exec_()
>
> Then from the main thread (i.e. after the text.connect) start your
> thread by calling a.start(). You might need to add another function to
> your thread-class that starts the timer, but I'm not sure might as well
> just work as is...

Thank you, Andreas. The example I posted didn't quite work, the label text 
wasn't updated, but the event loop runs as I wanted. The actual application I 
am working on is now working as I had hoped it would.

I will try to post a working version of my example, but I am on a deadline and 
don't have time to do it right now.

Thanks again,
Darren


More information about the PyQt mailing list