9.4. Summary

Constructing a responsive user interface is not all that difficult if you know the techniques. It is important to remember, when writing a GUI application, that your code needs to divide its time between performing work and interacting with the user. One should not be sacrificed for the other. In particular, it is important to stop thinking in a linear way when coding a long task—the rest of your application cannot wait for the long task. You should ask yourself the following questions:

  • Where is a good place to stop working on the long job and return control to the event loop?

  • How long should the long job continue before returning control to the event loop?

  • What information do I need to save so that I can pick up where I left off when control is returned from the event loop to the method carrying out the long job?

Answering these questions will help you effectively use QTimer to perform long jobs.

You can speed up window updates by using the double-buffer technique. This can keep you from having to unnecessarily re-create your window's contents. This technique can also help reduce flicker by updating the entire window at once rather than drawing multiple objects on the window.