[PySide] most basic QThread problem

Dan McCombs dmccombs at dyn.com
Mon Dec 16 14:54:35 CET 2013


Hey Frank,

I think the real reason you're getting that message isn't the subclassing
piece, but that your program is exiting before the thread has finished.
There's nothing in your application to keep it running after running the
doIt method, so it exits, and destroys the thread. Normally you would have
a QApplication instance and be calling the exec_ method on that after doIt
to start your application's event loop and keep it running, until it was
quit via some user interaction.

-Dan

[image: Dyn logo, Dyn.com] <http://dyn.com/>
<http://twitter.com/dyn><http://twitter.com/dyninc>
   [image: Dyn facebook account] <http://facebook.com/dyn>   [image: Dyn
LinkedIn account] <http://linkedin.com/company/dyn>

Dan McCombs  / Senior Software Engineer
 603 296 1568      @danmccombs <http://twitter.com/danmccombs/>


On Mon, Dec 16, 2013 at 2:01 AM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:

> Hi all,
>
>
> I am playing with simple QThread object and am getting the ol' "QThread:
> Destroyed while thread is still running" error.
>
> I have searched the web quite a bit now and keep running into examples
> that do exactly what I am doing, except it seems to work for others.
> Can somebody tell me where I'm going wrong with this bare bones examples
> please?
>
> Cheers,
> frank
>
> from PySide import QtCore
> import time
>
> class MyThread(QtCore.QThread):
>
>      def __init__(self, parent=None):
>          super(MyThread, self).__init__(parent)
>
>      def run(self):
>          for i in xrange(10):
>              print i
>              time.sleep(1)
>
> class MainApp(QtCore.QObject):
>
>      def __init__(self, parent=None):
>          super(MainApp, self).__init__(parent)
>          self.thread = MyThread(self)
>
>      def doIt(self):
>          self.thread.start()
>
> if __name__ == '__main__':
>      a = MainApp()
>      a.doIt()
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131216/2f6f4dd9/attachment.html>


More information about the PySide mailing list