I am building a QWindow with PyQt. I have a window that has some check points. On the button press, the QThread is being initialized and is supposed to run bunch of functions that are doing something with some other application and symultaniously supposed to update the GUI. In order to update the GUI I used the SIGNAL that is connected to the QThread. The issue that I'm having is with the QThread running backwards. I created the object that is type QThread and reimplemented the run function to do some printing and send some SIGNALS like so (I Used self.children() just as an example for printing, and r variables as a results from my functions.):
class Process(QtCore.QThread):
def __init__(self, items):
QtCore.QThread.__init__(self)
self.__items = items
def run(self):
print "PRINTING STATEMENT NO. 1"
print "PRINTING STATEMENT NO. 2"
print "CHILDREN: ", self.children()
self.emit(QtCore.SIGNAL("updateProcess"), 0, True, 0)
# Here would be the first function
r = [1, 2, 3]
time.sleep(3)
if r and r != []:
self.emit(QtCore.SIGNAL("updateProcess"), 0, False, 1)
else:
self.emit(QtCore.SIGNAL("updateProcess"), 0, True, 1)
self.emit(QtCore.SIGNAL("updateProcess"), 0, True, 0)
# Here would be the second function
r = None
if r and r != []:
self.emit(QtCore.SIGNAL("updateProcess"), 1, False, 1)
else:
self.emit(QtCore.SIGNAL("updateProcess"), 1, True, 1)
So when I click the button that starts the thread, if I run it with run() command (which I know is wrong and doesn't start the process in a new thread just runs the function) it runs fine, and everything is in order except that it doesn't update the GUI until it finishes since it's not a new thread... But the printing is in the correct order:
PRINTING STATEMENT NO. 1
PRINTING STATEMENT NO. 2
CHILDREN: [<PyQt4.QtCore.QObject object at 0xed84f28>]
Once I try to run the QThread with the start() function, it runs the whole function backwards and prints out:
[<PyQt4.QtCore.QObject object at 0x18e33cc8>] CHILDREN:
PRINTING STATEMENT NO. 2
PRINTING STATEMENT NO. 1`
Does anyone know why is this happening?? Also if someone has any other suggestion how to create a Thread that is going to run in the background and update the GUI please feel free to tell me since this is the only one that I could come up with and apparently is not working properly :/. Thanks in advance.