Important: Please read the Qt Code of Conduct -

Displaying Buffer data on Qlabel

  • Hi,
    I have a buffer data of color format YUY2 /UYVY/NV12/NV21 etc.

    How do I display/render the buffer using qlabel??

  • Lifetime Qt Champion


    You'll have to convert it to one of the supported QPixmap type first.

  • @SGaist
    Thank you for your reply.

    Below is my code for displaying/rendering "RGB" buffer on a Qlabel.

         QImage  *img = new QImage(camera->width ,camera->height, 
     uint8_t *l_ui_arr = new uint8_t[g_size_v4l2];
     if (!l_ui_arr)
        qDebug() << "Memory allocation failed for arr\n";
     camera->head.start // This is my buffer
     g_size_v4l2 // The size of the buffer
    camera->height // Height of my image
    camera->width // width of my image
    for(uint32_t l_height = 0; l_height < camera->height; l_height++)
      for(uint32_t l_width = 0; l_width < camera->width; l_width++)
           QRgb value = qRgb(l_ui_arr[l_ui_arrayIndex], l_ui_arr[l_ui_arrayIndex+1], l_ui_arr[l_ui_arrayIndex+2]);
           l_ui_arrayIndex = l_ui_arrayIndex+3;
           img->setPixel(l_width, l_height,value);

    Now, when I get buffer of any other format such as NV12/NV21/UYVY etc.

    How do I convert it to the supported QPixmap type??

  • You probably have to do the conversion from NV12/UYVY etc to RGB yourself then generate the pixmap.
    There's lots of code available to show how to do this. Check StackOverflow.

Log in to reply