My goal for a task is to allow one button press to start two processes, both running simultaneously on different QThreads.
My code is structured like this (simplified)
class Main_Window():
# My UI stuff goes here
class worker1(QtCore.QObject):
def __init__(self):
...
def run1():
...
class worker2(QtCore.QObject):
def __init__(self):
...
def run2():
...
app = QtGui.QApplication(sys.argv)
myapp = Main_Window()
thr1 = QtCore.QThread()
thr2 = QtCore.QThread()
work1 = worker1()
work2 = worker2()
work1.moveToThread(thr1)
work2.moveToThread(thr2)
# I have a signal coming in from main thread
app.connect(myapp, QtCore.SIGNAL('start1'), work1.run1())
app.connect(myapp, QtCore.SIGNAL('start1'), work2.run2())
thr1.start()
thr2.start()
Is this kind of QThread coding incorrect if I want to setup two Qthreads?
I am getting a "Segmentation fault" when I try to start the program, but as soon as I take the second app.connect away, it runs fine.
I was wondering if anyone can tell me where I've gone wrong.
Thanks!