<div dir="ltr"><div>Hello all,<br><br></div><div>There are some fantastic examples on the web about qthread, but none of which seem to be working for me. :/<br><br></div><div>I have a very simple program, in fact I want it to be the most simple qthread example on the web.</div>
<div><br></div><div style>My mainfile.py:</div><div><br></div><div><div>#!/usr/bin/env python3</div><div><br></div><div>import sys, time</div><div>from PyQt4 import QtCore, QtGui</div><div>import copytextfromlineedit</div>
<div><br></div><div>class StartQT(QtGui.QMainWindow):</div><div><span class="" style="white-space:pre">   </span>def __init__(self, parent=None):</div><div><span class="" style="white-space:pre">           </span>QtGui.QMainWindow.__init__(self, parent)</div>
<div><span class="" style="white-space:pre">            </span>self.ui = copytextfromlineedit.Ui_MainWindow()</div><div><span class="" style="white-space:pre">             </span>self.ui.setupUi(self)</div><div><span class="" style="white-space:pre">              </span>QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.get)</div>
<div><br></div><div><span class="" style="white-space:pre">   </span>def get(self):</div><div><span class="" style="white-space:pre">             </span>w = Worker()</div><div><span class="" style="white-space:pre">               </span>w.start()</div>
<div><br></div><div><br></div><div>class Worker(QtCore.QThread):</div><div><span class="" style="white-space:pre">      </span>def __init__(self, parent=None):</div><div><span class="" style="white-space:pre">           </span>QtCore.QThread.__init__(self)</div>
<div><span class="" style="white-space:pre">            </span>print("hello world")</div><div><span class="" style="white-space:pre">                             </span></div><div><span class="" style="white-space:pre">   </span>def __del__(self):</div>
<div><span class="" style="white-space:pre">            </span>self.wait()</div><div><br></div><div><span class="" style="white-space:pre">       </span>def run(self):</div><div><span class="" style="white-space:pre">             </span>print("run")</div>
<div><span class="" style="white-space:pre">            </span>for value in range(1,101):</div><div><span class="" style="white-space:pre">                 </span>time.sleep(0.5)</div><div><span class="" style="white-space:pre">                    </span>print(value)</div>
<div><span class="" style="white-space:pre">            </span></div><div><span class="" style="white-space:pre">           </span></div><div>app = QtGui.QApplication(sys.argv)</div><div>myapp = StartQT()</div><div>myapp.show()</div><div>sys.exit(app.exec_())</div>
<div><br></div>
<div><br></div><div><br></div><div style>is my main and this is my copytextfromlineedit.py</div><div style><br></div><div style><br></div><div style><br></div><div style><div>from PyQt4 import QtCore, QtGui</div><div><br>
</div><div>try:</div><div>    _fromUtf8 = QtCore.QString.fromUtf8</div><div>except AttributeError:</div><div>    _fromUtf8 = lambda s: s</div><div><br></div><div>class Ui_MainWindow(object):</div><div>    def setupUi(self, MainWindow):</div>
<div>        MainWindow.setObjectName(_fromUtf8("MainWindow"))</div><div>        MainWindow.resize(115, 78)</div><div>        self.centralwidget = QtGui.QWidget(MainWindow)</div><div>        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))</div>
<div>        self.pushButton = QtGui.QPushButton(self.centralwidget)</div><div>        self.pushButton.setGeometry(QtCore.QRect(0, 10, 113, 27))</div><div>        self.pushButton.setObjectName(_fromUtf8("pushButton"))</div>
<div>        self.progressBar = QtGui.QProgressBar(self.centralwidget)</div><div>        self.progressBar.setGeometry(QtCore.QRect(0, 50, 113, 23))</div><div>        self.progressBar.setProperty("value", 24)</div>
<div>        self.progressBar.setObjectName(_fromUtf8("progressBar"))</div><div>        MainWindow.setCentralWidget(self.centralwidget)</div><div><br></div><div>        self.retranslateUi(MainWindow)</div><div>        QtCore.QObject.connect(self.progressBar, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")), self.pushButton.click)</div>
<div>        QtCore.QMetaObject.connectSlotsByName(MainWindow)</div><div><br></div><div>    def retranslateUi(self, MainWindow):</div><div>        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))</div>
<div>        self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "TAKE IT", None, QtGui.QApplication.UnicodeUTF8))</div><div><br></div><div><br></div><div><br></div><div style>I want the progress bar to update while the program is running, but I haven't even got that far because the GUI freezes up like so:</div>
<div style><br></div><div style><a href="http://ikt.id.au/blog/wp-content/uploads/2013/04/notresponding.png">http://ikt.id.au/blog/wp-content/uploads/2013/04/notresponding.png</a><br></div></div><div style><br></div><div style>
I can see the thread still running and printing out numbers even after I force close the gui, so it doesn't make sense to me.</div><div style><br></div><div style>I know this is quite a noob question, but if anyone is able to keep the gui alive while the thread runs I would be very appreciative.</div>
<br>- ikt<br></div></div>