S
S
Semyon Beloglazov2017-07-26 10:03:16
Python
Semyon Beloglazov, 2017-07-26 10:03:16

How to catch finished() signal for a separate thread in pyqt5?

In general.
The following code creates an object of the QThread instance class

# Создаем новый поток и прослушиваем слот
        self.myThread = jobThread(self.isJobStopped, self.spinBox.value()) # Создаем обьект класса и передаем ему нужные аргументы
        self.myThread.jobSignal.connect(self.addLog) # Прослушиваем кастомный сигнал
        self.myThread.start() # Создаем поток

When I need, I stop the thread with this code:
self.myThread.terminate()
After it has been stopped, I need to hang my function on it, no matter which one.
The documentation says that QThread objects have a finished () signal, by which this can be tracked.
Everything would be fine, in PyQt4 it works fine for this code:
self.connect(self.myThread, SIGNAL("finished()"), self.addLog('Программа завершена'))

But in PyQt5, the signal system has changed.
self.connect(self.myThread, SIGNAL("jobSignal(str)"), self.addLog)  # PyQt4
self.myThread.jobSignal.connect(self.addLog)  # PyQt5

The question becomes, how do I listen to the finished() signal?
I tried like this:
self.myThread.finished().connect(self.addLog)
But it throws the error "Native qt signal is not callable"
How can I deal with it?
Urgently need a solution, it was not found in the documentation (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Semyon Beloglazov, 2017-07-27
@Batlab

Problem solved.
In PyQt5, you need to call not finished() but finished.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question