Hi all,
I’m writing a pyqt5 projects with threads. I would like receive a variable from thread function when finished emit is received.
I tried with following simply code:
class connectionToMachine(QtCore.QThread):
finished = QtCore.pyqtSignal(object)
def __init__(self):
QtCore.QThread.__init__(self)
def run(self):
self.checkConnection = False
def check():
out = True
return out
check = connection()
self.finished.emit(check)
class Ui(QMainWindow):
checkCode = False
def __init__(self):
super().__init__()
...
def onCheckThreadFinished(self, check):
print(check)
def onConnectionClicked(self):
self.threadConnection = QThread()
self.workerConnection = connectionToMachine()
self.workerConnection.moveToThread(self.threadConnection)
self.threadConnection.finished.connect(self.onCheckThreadFinished)
self.threadConnection.started.connect(self.workerConnection.run)
self.threadConnection.started.connect(self.threadConnection.quit)
self.threadConnection.started.connect(self.workerConnection.deleteLater)
self.threadConnection.started.connect(self.threadConnection.deleteLater)
self.threadConnection.start()
but doesn’t work
Maybe is possible change checkCode variable in thread function and return new value when thread finished is emitted?
thank you very much