I am working on a complex and poorly commented Qt-based Python application. It employs a PySide.QtCore.QTimer.singleShot(int,slot) timer to delay the execution of a slot within a thread, and I am confused about how this timer works.
Here is a MWE. This example uses the approach of subclassing QThread and reimplementing run(). I put the following in a file called timertester.py:
print('end of delayed_print()')
from timertester import SubClassThread
print('Test: QThread subclassing')
app = PySide.QtCore.QCoreApplication()
sct = SubClassThread()
Test: QThread subclassing
end of delayed_print()
The default implementaion of
QThread.exec(), which starts the thread's own event-loop. A
QTimer requires a running event-loop, and its
timeout() signal will be emitted in the thread it is started in. Your implementation of
run() does not start an event-loop, so the timer will do nothing.