I had a program working that was getting jpg images over the network loading it into a QPixmap with the loadFromData() method and assigning the QPixmap to a QLabel with setPixmap().
The user interface was not very responsive so I decided to speed things up a little bit I by moving the jpeg decoding over to a separate thread. I found out that QPixmap couldn't run in a secondary thread so my plan was to load the data into the QImage on the secondary thread and then on the GUI thread load the QImage into the QPixmap with fromImage().
When I did this I ended up with a white image being displayed on the screen. To verify that things were working correctly I wrote the JPEG data to a file before loading into a QImage and then had QImage save it to another file. Both of these two files have the images I expect. I even tried moving the QImage loadFromData() back to the GUI thread just to rule out threading issues.
I know it's got to be something I'm doing wrong but it seems so straightforward. Here's the code snippet of what I'm doing.
bool foobar(uchar *p_imgbuf, int img_size)
{
status = image.loadFromData(p_imgbuf, img_size,"JPG");
my_pixmap.fromImage(image);
p_label->setPixmap(my_pixmap);
}
bool foobar(uchar *p_imgbuf, int img_size)
{
QImage image;
QPixmap my_pixmap;
QLabel *p_label;
p_label = new QLabel();
status = image.loadFromData(p_imgbuf, img_size,"JPG");
my_pixmap.fromImage(image);
p_label->setPixmap(my_pixmap);
}
To copy to clipboard, switch view to plain text mode
Bookmarks