<div dir="ltr"><div><div><div>Hey,<br><br></div>I found a solution! I've created the thread in the main:<br><br>if __name__ == "__main__":<br>
    qApp = QtGui.QApplication([" "])<br>
    aw = ApplicationWindow()<br>
    aw.showMaximized()<br>
    thread = AThread()<br>
    sys.exit(qApp.exec_())<br><br></div>But I "run" thread.start() only when clicking on my button. I'll try to post my code soon here to have your comments on it. I'm physicist so I'm not coding very well :) but It's better if the code is well structured and not only if it's working (as we love to do as physicist). Thanks again!<br>
<br></div>Fabien<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/1/15 David Hoese <span dir="ltr"><<a href="mailto:dhoese@gmail.com" target="_blank">dhoese@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 1/15/13 9:46 AM, Fabien Lafont wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've changed the program according to your remarks. It works fine! I have only one problem. I want to start the new thread when I clik on a QPushButton but If I just remove<br>
<br>
    thread = AThread()<br>
    thread.start()<br>
<br>
from<br>
<br>
if __name__ == "__main__":<br>
    qApp = QtGui.QApplication([" "])<br>
    aw = ApplicationWindow()<br>
    aw.showMaximized()<br>
    thread = AThread()<br>
    thread.start()<br>
    sys.exit(qApp.exec_())<br>
<br>
<br>
and I create a single button :<br>
<br>
def demarrer(self):<br>
      thread = AThread()<br>
      thread.start()<br>
<br>
<br>
The program crashes and "say":    QThread: Destroyed while thread is still running<br>
<br>
<br>
Do you have any idea?<br>
</blockquote></div>
Without trying this myself, I'm guessing what's happening is that the thread object is getting destroyed/garbage collected after the "demarrer" function is finished.  When that function gets called the "thread = AThread()" line creates the "AThread" instance and assigns it to the local variable name "thread", which is a handle to the actual OS level thread.  When the function exits that local variable "thread" does not exist anymore and will eventually be garbage collected.  This is probably where the error message is coming from because the QThread object ("thread") is destroyed (garbage collected) while the low-level thread is still running.<br>

<br>
My suggestion, as a starting point, would be to create a class instance attribute by doing "self.child_thread = AThread()".  This way when the function exists there is still a pointer to the QThread object.  Don't forget you still need to kill the thread off before the application finishes, otherwise you'll probably still get this error after everything closes.  I think you were using a qApp.exit signal for that before.  Hope this helps.<br>

<br>
-Dave<br>
<br>
</blockquote></div><br></div>