I am trying to create a simple multi-threaded program in which I have a method that does some long processing and a widget that displays a loading bar and a cancel button.
My problem is that no matter how I implement the threads, they are not really threads - the user interface is blocked after the thread starts working. I read every tutorial and posted about it, and now I resort to asking the community to try to solve my problem, because I'm at a loss!
I initially tried to subclass QThread until the internet said it was wrong. Then I tried to use the moveToThread method, but it made a null difference.
Initialization Code:
loadingThreadObject = LoadThread(arg1)
loadingThread = PythonThread()
loadingThreadObject.moveToThread(loadingThread)
loadingThread.started.connect(loadingThreadObject.load)
loadingThread.start()
PythonThread class (obviously, QThreads are listened to in pyQt and will not start if you do not):
class PythonThread (QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
def start(self):
QtCore.QThread.start(self)
def run(self):
QtCore.QThread.run(self)
LoadThread Class:
class LoadThread (QtCore.QObject):
results = QtCore.Signal(tuple)
def __init__ (self, arg):
super(QtCore.QObject, self).__init__()
self.arg = arg
def load (self):
loaded = True
errors = []
self.results.emit((loaded, errors))
Any help is much appreciated!
Thanks. Ben.
source
share