3

I use a QLabel to display a pseudo-video stream. Since I have extensive calculation to do on the pixels, I use the QImage bits() function and then convert it to a pixmap to show it on the QLabel. So far I was using:

for(...)
{
    computeImage(&myImage);
    myLabel->setPixmap(QPixmap::fromImage(myImage));
}

However, since QPixmap::fromImage(...) function always create a new QPixmap object, I tried the following who should be more efficient:

QPixmap myPixmap;
for(...)
{ 
    computeImage(&myImage);
    bool b = myPixmap.convertFromImage(myImage);
    myLabel->setPixmap(myPixmap);
}

It work fine for the first display but it doesn't refresh after that. The "b" variable is always true so the conversion worked well. I even tried to repaint() or update() the label, but it doesn't work. The label still display the very first image forever.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

1

What is your frames per second (fps)? Can you try putting some intervals between images? I think update() is also needed.

Lwin Htoo Ko
  • 2,326
  • 4
  • 26
  • 38
  • I think you might be right. Its probably looping fast and not letting the event loop process. It may need calls to qApp.processEvents – jdi Jun 19 '12 at 02:12
  • In fact the for loop was only to simplify the code example. (Sorry for that) In fact the for loop is a slot function that is called about 7 times per second. So it is not a time issue. I also already tried uptate() as I previously mentionned and it didn't work. I even put a qApp.processEvents and it still don't work. Any other idea? Thanks – user1159845 Jun 19 '12 at 12:28