Displaying sequence of images from separate thread
-
Hi,
I want to display a sequence of images with about 10-20fps using QLabel. Since the images are created by a separate thread, I use a signal/slot construction to avoid thread safety issues (see code below). All in all it works well, but some images get sporadically lost, i.e., they are not displayed. Adding a call to show() doesn't help. Any ideas what's going wrong? Thanks a lot in advance for your help and sorry if this is a newbie question!
Regards
@class gui: public QWidget {
Q_OBJECT
public:
gui();
void nextImage(QImage img);
...
signals:
void signalImage(QImage img);
public slots:
void setImage(QImage img);
private:
QLabel *label;
...
}gui::gui() {
label = new QLabel(...);
...
QObject::connect(this, SIGNAL(signalImage(QImage)), this, SLOT(setImage(QImage)));
}void gui::nextImage(QImage img) {
emit signalImage(img);
}void gui::setImage(QImage img) {
label->setPixmap(QPixmap::fromImage(img));
// label->show();
}
@
Main thread:
@ gui myGui;@Application thread:
@ QImage img(...);
myGui->nextImage(img);@ -
Hi and welcome to devnet,
Your code seems a bit convoluted to to achieve what you want, maybe have a look at the "mandelbrot example":http://qt-project.org/doc/qt-4.8/threads-mandelbrot.html
It explains a similar setup as yours (although the image generation will differ)Hope it helps