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

Damien R damien.rg at gmail.com
Tue Oct 20 17:36:39 CEST 2009


Hi,

I have to show images from several cameras, but after a while the widget
do not update the content. If I hide the widget and show it again, the
content is updated. To reproduce this problem the widget must stay above
other windows or must be in fullscreen and it occurs some time (after 30
minutes).
The code below illustrates the problem.

#include <boost/thread.hpp>
#include <QDebug>
#include <QApplication>
#include <QImage>
#include <QPainter>
#include <QWidget>

static const std::size_t WIDTH = 640;
static const std::size_t HEIGHT = 480;

class MyWidget : public QWidget
{
public:
  MyWidget() :
    image(WIDTH, HEIGHT, QImage::Format_RGB888)
  {
    setFixedSize(QSize(WIDTH / 2, HEIGHT / 2));
  }
  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);
  }

private:
  boost::mutex mutex_;
};

static MyWidget * widget = 0;

void update_image(MyWidget * widget)
{
  std::size_t i = 0;
  while(1) {
    i += 25;
    i %= 1000;
    widget->setImage(i);
  }
}

int main(int argc, char * argv[]) {
  QApplication app(argc, argv);
  MyWidget myWidget;
  myWidget.show();
  widget = &myWidget;
  boost::thread worker(boost::bind(update_image, widget));
  boost::thread worker1(boost::bind(update_image, widget));
  boost::thread worker2(boost::bind(update_image, widget));
  boost::thread worker3(boost::bind(update_image, widget));
  app.exec();
  return 0;
}

I have a debian sid version with qt 4.5.3-4.

Thanks in advance.

--

Damien R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091020/c71e78e6/attachment.html 


More information about the Qt-interest-old mailing list