title: How to send image frames from C++ to QML continuously
body: <p>I want to send image frames from C++ to a slot in my QML File continuously. Here I did the C++ coding only to get the image frame from the camera, but I need to send that image frame to QML using some method (signal slots,registry). And I need to know which QML elements can receive my image frames continuously and display them on the screen.     </p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QDataStream&gt;
  #include &lt;QString&gt;
  #include &lt;QDebug&gt;
  #include &lt;QBuffer&gt;
  #include &lt;typeinfo&gt;
  #include "capturethread.h"
  #include &lt;iostream&gt;
  #include &lt;QFile&gt;
  CaptureThread::CaptureThread(QWidget *parent) :
  QThread(parent)
  {
  this-&gt;parent=(videowidget*)parent;
  devam=false;
  fd = -1;
  }
  
  void CaptureThread::run(){
  fd = -1;
  dev_name = "/dev/video0";
  fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
  if (fd &lt; 0) {
         qDebug("Cannot open device");
         //exit(EXIT_FAILURE);
         return;
  }
  static struct v4lconvert_data *v4lconvert_data;
  static struct v4l2_format src_fmt;
  static unsigned char *dst_buf;
  CLEAR(fmt);
  fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  fmt.fmt.pix.width       = 640;
  fmt.fmt.pix.height      = 480;
  fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
  fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
  xioctl(fd, VIDIOC_S_FMT, &amp;fmt);
  if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) {
         printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
         //exit(EXIT_FAILURE);
         return;
  }
  if ((fmt.fmt.pix.width != 640) || (fmt.fmt.pix.height != 480))
         printf("Warning: driver is sending image at %dx%d\n",
                 fmt.fmt.pix.width, fmt.fmt.pix.height);
  
  v4lconvert_data = v4lconvert_create(fd);
  if (v4lconvert_data == NULL)
      qDebug("v4lconvert_create");
  if (v4lconvert_try_format(v4lconvert_data, &amp;fmt, &amp;src_fmt) != 0)
      qDebug("v4lconvert_try_format");
  xioctl(fd, VIDIOC_S_FMT, &amp;src_fmt);
  dst_buf = (unsigned char*)malloc(fmt.fmt.pix.sizeimage);
  
  CLEAR(req);
  req.count = 2;
  req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  req.memory = V4L2_MEMORY_MMAP;
  xioctl(fd, VIDIOC_REQBUFS, &amp;req);
  
  buffers = (buffer*)calloc(req.count, sizeof(*buffers));
  for (n_buffers = 0; n_buffers &lt; req.count; ++n_buffers) {
         CLEAR(buf);
  
         buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
         buf.memory      = V4L2_MEMORY_MMAP;
         buf.index       = n_buffers;
  
         xioctl(fd, VIDIOC_QUERYBUF, &amp;buf);
  
         buffers[n_buffers].length = buf.length;
         buffers[n_buffers].start = v4l2_mmap(NULL, buf.length,
                       PROT_READ | PROT_WRITE, MAP_SHARED,
                       fd, buf.m.offset);
  
         if (MAP_FAILED == buffers[n_buffers].start) {
                 qDebug("mmap");
                 //exit(EXIT_FAILURE);
                 return;
         }
  }
  
  for (int i = 0; i &lt; n_buffers; ++i) {
         CLEAR(buf);
         buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
         buf.memory = V4L2_MEMORY_MMAP;
         buf.index = i;
         xioctl(fd, VIDIOC_QBUF, &amp;buf);
  }
  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  
  xioctl(fd, VIDIOC_STREAMON, &amp;type);
  
  int di=0;
  char header[]="P6\n640 480 255\n";
  while(devam){
      /* bu döngü datanın birikmesini sağlıyor */
      do {
              FD_ZERO(&amp;fds);
              FD_SET(fd, &amp;fds);
  
              /* Timeout. */
              tv.tv_sec = 2;
              tv.tv_usec = 0;
  
              r = select(fd + 1, &amp;fds, NULL, NULL, &amp;tv);
      } while ((r == -1 &amp;&amp; (errno = EINTR)));
      if (r == -1) {
              qDebug("select");
              //exit(1) ;
              return;
      }
  
      CLEAR(buf);
      buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
      buf.memory = V4L2_MEMORY_MMAP;
      xioctl(fd, VIDIOC_DQBUF, &amp;buf);
  
      try{
  
      if (v4lconvert_convert(v4lconvert_data,
                              &amp;src_fmt,
                              &amp;fmt,
                              (unsigned char*)buffers[buf.index].start, buf.bytesused,
                              dst_buf, fmt.fmt.pix.sizeimage) &lt; 0) {
              if (errno != EAGAIN)
                      qDebug("v4l_convert");
  
      }
  
  
      unsigned char* asil=(unsigned char*)malloc(fmt.fmt.pix.sizeimage+qstrlen(header));
      memmove(asil, dst_buf, fmt.fmt.pix.sizeimage);
      memmove(asil+qstrlen(header), asil, fmt.fmt.pix.sizeimage);
      memcpy(asil,header,qstrlen(header));
  
      QImage qq;//=new QImage(dst_buf,640,480,QImage::Format_RGB32);
  
      if(qq.loadFromData(asil,fmt.fmt.pix.sizeimage+qstrlen(header),"PPM")){
          if(parent-&gt;isVisible()){
              QImage q1(qq);
              qDebug()&lt;&lt;"qimage"&lt;&lt;q1;
              parent-&gt;img=q1;
              parent-&gt;update();
            //this-&gt;msleep(50);
          }
      //qApp-&gt;processEvents();
          if(asil)
              free(asil);
      }
      }catch(...){}
      xioctl(fd, VIDIOC_QBUF, &amp;buf);
      di++;
  }
  try{
  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  xioctl(fd, VIDIOC_STREAMOFF, &amp;type);
  for (int i = 0; i &lt; n_buffers; ++i)
         v4l2_munmap(buffers[i].start, buffers[i].length);
      v4l2_close(fd);
  }catch(...){}
  }
  </code></pre>
  
  <p>The above code is based on the <code>QThread</code> class, I need to call the thread from QML and receive image frames.</p>