title: Showing continuous stream of QImages
body: <p>I have a set of QImages which come to a function (after a fixed interval of 4 seconds) and the function's job is to update the QLabel to show the new image.</p>
  
  <p>While doing this, I can see a very obvious delay in the image rendering.</p>
  
  <p>I had also followed the suggestions on the link:</p>
  
  <p><a href="https://stackoverflow.com/questions/22353080/efficient-way-of-displaying-a-continuous-stream-of-qimages">Efficient way of displaying a continuous stream of QImages</a></p>
  
  <p>But, even with using ImageDisplay  in the link above, I can see a delay in image rendering.</p>
  
  <p>Can anyone please suggest the best way to do this?</p>
  
  <p>Below is the code.. The images required for the code to run are located at:</p>
  
  <p><a href="https://www.dropbox.com/sh/jiqdfqoiimjs7ei/AAAXezUeeCFyZXjNNOTmWZVga?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/sh/jiqdfqoiimjs7ei/AAAXezUeeCFyZXjNNOTmWZVga?dl=0</a></p>
  
  <pre><code>#include &lt;QDialog&gt;
  #include &lt;QtGui&gt;
  #include &lt;QtCore&gt;
  #include &lt;QApplication&gt;
  #include &lt;QWidget&gt;
  #include &lt;QImage&gt;
  
  class imageDisplay : public QWidget
  {
      public:
          imageDisplay(QWidget*);
          ~imageDisplay();
          void setImage(QImage* img);
  
      private:
          QImage* m_image;
  
  protected:
          void paintEvent(QPaintEvent* evt);
  };
  
  imageDisplay::imageDisplay(QWidget* parent) : QWidget(parent)
  {
      m_image = 0;
      setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  }
  
  imageDisplay::~imageDisplay()
  {
  }
  
  void imageDisplay::setImage(QImage* img)
  {
      m_image = img;
      repaint();
  }
  
  void imageDisplay::paintEvent(QPaintEvent*)
  {
      if(!m_image) return;
      QPainter painter(this);
      painter.drawImage(rect(), *m_image, m_image-&gt;rect());
  }
  
  ////////////////////////////////////
  //
  int main(int arc, char ** argv)
  {
      QApplication theApp(arc, argv, true);
  
      QDialog* dlg = new QDialog();
  
      imageDisplay* wgt = new imageDisplay(dlg);
      wgt-&gt;resize(600,400);
      dlg-&gt;show();
  
      for(int i = 0 ; i &lt;= 19; ++i)
      {
          sleep(1);
          QString fileName = "aaa" + QString::number(i) + ".png";
          QImage* img = new QImage(fileName);
          wgt-&gt;setImage(img);
      }
  
      return theApp.exec();
  }
  </code></pre>