I have a software that sends JPGs over the network to a GUI client that is supposed to display those images. I basically want to display them to a qt window but I’m having problems with how qt displays consecutive JPGs. I made a test to see if I’m getting the image correctly by printing it to a file and that checks out fine. Here’s the main code:
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QApplication app(argc, argv);
CameraWindow cw;
cw.show();
//app.setActiveWindow(&cw);
cw.getData(); // this paints the window
return app.exec();
}
Here’s the code that initializes the widget:
class CameraWindow : public QDialog {
Q_OBJECT
public:
bool serverConnected;
void getData();
CameraWindow()
{
imgl = new QLabel;
widget.scrollImage->setWidget(imgl);
widget.scrollImage->setBackgroundRole(QPalette::Dark);
}
QLabel *imgl;
virtual ~CameraWindow();
private:
Ui::CameraWindow widget;
};
This is the relevant part of the code that is supposed to paint the image to the screen which is inside an infinite loop:
getData() called from main:
while (myrval < Header.imageSize) {
myrval = myrval + recv(msgsock, (char*) ((int) buff + myrval),
Header.imageSize- myrval, 0);
}
//buff contains the jpg at this point
QPixmap imgjpg;
imgjpg.loadFromData((const unsigned char*)buff, Header.imageSize, "JPG");
//scroll image is the parent that displays child
//in this case, the label
imgl->setPixmap(imgjpg);
I got this to work for just one image that was loaded from a file but when I use the same method for a set of streaming images, this doesn’t work. I’m new to Qt so I’m sure I have a subtle mistake.
Many thanks!
Because you are in a infinite loop, the Qt may not have chance to handle event. Could you try to call QCoreApplication::processEvents after you setPixmap?