Updating progress bars using threads bound with a locking mechanism
This recipe will help you understand how two threads can avoid ambiguity by making use of locks. That is how shared resources can be accessed and manipulated by two threads simultaneously, without giving ambiguous results.
We will be making use of two progress bars in this recipe. One progress bar will represent progress in downloading a file, and the other progress bar will represent progress in scanning for viruses on the current drive. Only one progress bar will progress at a time.
How to do it...
The following steps will help you understand how two threads can run simultaneously, updating a common shareable resource, without giving ambiguous results:
- Let's create an application based on the
Dialog without Buttons
template. We need two pair of QLabel and QProgressBar widgets in this application. - Add a
QLabel
and aQProgressBar
widget to the form by dragging and dropping aLabel
widget on the form and, below theLabel
widget...