title: show webcam stream from OpenCV with Qt
body: <p>so i can see my webcam stream with OpenCV with imshow with this simple code</p>
  
  <pre><code>int main(int, char**)
  {
      VideoCapture cap(0); 
      Mat edges;
      namedWindow("webcam", 1);
      while (true)
      {
          Mat frame;
          cap &gt;&gt; frame; 
          imshow("webcam", frame);
          if (waitKey(30) &gt;= 0) break;
      }
      return 0;
  }
  </code></pre>
  
  <p>now what i want to is to show the image from OpenCV in QImage in Widget on QT
  Here is a conversion from cv::Mat to QImage</p>
  
  <pre><code>QImage Mat2QImage(cv::Mat const&amp; src)
  {
      cv::Mat temp; 
      cvtColor(src, temp, CV_BGR2RGB); 
      QImage dest((const uchar *)temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
      dest.bits(); 
      // of QImage::QImage ( const uchar * data, int width, int height, Format format )
      return dest;
  }
  </code></pre>
  
  <p>and the little code to show an image with QImage in QT</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      QImage myImage;
      myImage.load("a.png");
      QLabel myLabel;
      myLabel.setPixmap(QPixmap::fromImage(myImage));
      myLabel.show();
      return a.exec();
  }
  </code></pre>
  
  <p>i tried to combine them in this way, but no luck</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      VideoCapture cap(0);
  
      QImage myImage;
      QLabel myLabel;
      while (true)
      {
          Mat frame;
          cap &gt;&gt; frame; // get a new frame from camera
  
          myImage = Mat2QImage(frame);
          myLabel.setPixmap(QPixmap::fromImage(myImage));
      }
  
  
      myLabel.show();
  
      return a.exec();
  </code></pre>