title: Using QT to view streaming images from camera
body: <p>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:</p>
  
  <pre><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(&amp;cw);
      cw.getData();       // this paints the window  
      return app.exec();
  }
  </code></pre>
  
  <p>Here's the code that initializes the widget:</p>
  
  <pre><code>class CameraWindow : public QDialog {
      Q_OBJECT
      public:
      bool serverConnected;
      void getData();
      CameraWindow()
      {
          imgl = new QLabel;
          widget.scrollImage-&gt;setWidget(imgl);
          widget.scrollImage-&gt;setBackgroundRole(QPalette::Dark);
      }
      QLabel *imgl;
      virtual ~CameraWindow();
      private:
      Ui::CameraWindow widget;
  };
  </code></pre>
  
  <p>This is the relevant part of the code that is supposed to paint the image to the screen which is inside an infinite loop:</p>
  
  <p>getData() called from main:</p>
  
  <pre><code>while (myrval &lt; 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-&gt;setPixmap(imgjpg);
  </code></pre>
  
  <p>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.</p>
  
  <p>Many thanks!</p>