[Qt-interest] Widget does not update content after some time

Brad Howes howes at ll.mit.edu
Tue Oct 20 17:44:06 CEST 2009


On Oct 20, 2009, at 11:36 AM, Damien R wrote:

>   QImage image;
>   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();
>   }
>
> protected:
>   void paintEvent(QPaintEvent *)
>   {
>     QPainter painter(this);
>     boost::mutex::scoped_lock lock(mutex_);
>     painter.drawImage(rect(), image, image.rect(),
>                       Qt::AutoColor|Qt::ThresholdDither|
>                       Qt::ThresholdAlphaDither);
>   }


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.

Brad

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420








More information about the Qt-interest-old mailing list