Я обнаружил, что QThread.start()
моего приложения не выдает сигнал started()
, как указано в документации. претензии. Я подключил сигнал started()
к слоту, но он никогда не срабатывает, пока я не вызову явно started.emit()
.
Я сократил свой код до работоспособной демонстрации проблемы. Как видите, сигнал на самом деле подключен к слоту, а поток на самом деле запущен start()
, так что ни в том, ни в другом нет проблемы.
Что плохого в том, что started()
никогда не испускается?
#!/usr/bin/env python3
import PySide2.QtCore
import PySide2.QtWidgets
@PySide2.QtCore.Slot()
def test_receiver():
print('thread.started() signal received.')
if __name__ == '__main__':
app = PySide2.QtWidgets.QApplication()
app.processEvents()
thread = PySide2.QtCore.QThread()
thread.started.connect(test_receiver)
thread.start()
# The connection between signal and slot isn't the problem because
# the signal has actually connected, as evidenced if you uncomment the following line:
#
# thread.started.emit()
#
# So why is thread.started() never emitted after thread.start()?
while thread.isRunning():
print('Thread is running...')
PySide2.QtCore.QThread.sleep(1)
print('Everything quit.')