Reputation: 481
I'm trying to use a variable from one class in another, but I get the error, "run() missing 1 required positional argument: 'MyWindowClass'"
class TaskThread(QtCore.QThread):
updateProgressSignal = QtCore.pyqtSignal(int)
def run(self, MyWindowClass):
for i in range(101):
self.updateProgressSignal.emit(i)
print ( MyWindowClass.pbTimeUpdate )
time.sleep(MyWindowClass.pbTimeUpdate)
class MyWindowClass(QtGui.QDialog ):
def __init__(self, *args):
super(MyWindowClass, self).__init__(*args)
self.pbTimeUpdate = .2
self.myLongTask = TaskThread()
self.myLongTask.updateProgressSignal.connect (self.onProgress)
self.myLongTask.start()
def onProgress (self, val )
print (val)
I've tried making the variable global (declared outside both classes in same file), but updating the variable value in in one class, the other class still sees the original value)
What could be the issue?
Upvotes: 0
Views: 525
Reputation: 8437
This should work:
class MyWindowClass(QtGui.QDialog):
pbTimeUpdate = .2
class TaskThread(QtCore.QThread):
updateProgressSignal = QtCore.pyqtSignal(int)
def run(self):
for i in range(101):
self.updateProgressSignal.emit(i)
print(MyWindowClass.pbTimeUpdate)
time.sleep(MyWindowClass.pbTimeUpdate)
Upvotes: 1