- Create code to call the self.every_ten_seconds() method every ten seconds.
Assuming we're in the __init__() method of a class, it looks like this:
self.timer = qtc.QTimer()
self.timer.setInterval(10000)
self.timer.timeout.connect(self.every_ten_seconds)
- The following code uses QTimer incorrectly. Can you fix it?
timer = qtc.QTimer()
timer.setSingleShot(True)
timer.setInterval(1000)
timer.start()
while timer.remainingTime():
sleep(.01)
run_delayed_command()
QTimer is being used synchronously with the while loop. This creates blocking code. The same can be done asynchronously, like so:
qtc.QTimer.singleShot(1000, run_delayed_command)
- You've created the following word-counting worker class and want to move it to another thread to prevent large documents from slowing the GUI. It's not working, however...