[Qt-interest] Widget does not update content after some time
John McClurkin
jwm at nei.nih.gov
Wed Oct 21 13:36:27 CEST 2009
Damien R wrote:
> > Seeing two locks, I bet you have deadlock situation -- you've already
> > acquired the lock in setImage(), then you invoke update. However, you
> > still hold the lock. What happens if update() calls your paintEvent()
> > method for the same object? You attempt to lock again, but you already
> > hold the mutex. Deadlock.
>
> No, it is not a deadlock. update() add an event in the process event
> list of Qt so update() do not directly call paintEvent() as I understand
> the documentation of Qt. So this code is never equivalent to the
> following code :
> void setImage(std::size_t i)
> {
> boost::mutex::scoped_lock lock(mutex_);
> uchar * imageBuffer = image.bits();
> memset(imageBuffer, i * 25 % 255, WIDTH * HEIGHT * 3);
> paintEvent(0);
> }
>
> Moreover, the program is not frozen. Indeed, if I hide the widget and
> show it again, the content of the widget is updated.
>
> --
> Damien R
Well, you can test Brad's assumption easily enough
void setImage(std::size_t i)
{
{
boost::mutex::scoped_lock lock(mutex_);
uchar * imageBuffer = image.bits();
memset(imageBuffer, i * 25 % 255, WIDTH * HEIGHT * 3);
}
update();
}
This will release the mutex before update is called.
More information about the Qt-interest-old
mailing list