Results 1 to 2 of 2

Thread: Displaying Raw data on QLabel

  1. #1
    Join Date
    Nov 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Displaying Raw data on QLabel

    Hi, I have some problem in displaying unsigned char* data on QLabel.

    Following is my code.

    Originally data was "unsigned char*", but it has first converted to "const char*" because I had to write it to QDataStream.

    Anyway, i read "const char*" data by "in.readRawData", and converted it to unsigned char*.

    Qt Code:
    1. QBuffer buffer;
    2. QDataStream in(&buffer);
    3.  
    4. sharedMemory.create(1920 * 1080);
    5. buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
    6. buffer.open(QBuffer::ReadOnly);
    7. sharedMemory.unlock();
    8. sharedMemory.detach();
    9.  
    10. int r_width = 0;
    11. int r_height = 0;
    12. int r_cameraId = 0;
    13. int r_step = 0;
    14. int r_strlen = 0;
    15. in >> r_width >> r_height >> r_step >> r_cameraId >> r_strlen;
    16.  
    17. char* receive = new char[r_strlen];
    18. in.readRawData(receive, r_strlen);
    19. //unsigned char* r_receive = new unsigned char[r_strlen];
    20. //r_receive = (unsigned char*)receive;
    21.  
    22. QPixmap backBuffer = QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step, QImage::Format::Format_RGB888));
    23. ui.label->setPixmap(backBuffer.scaled(ui.label->size(), Qt::KeepAspectRatio));
    24. ui.label->show();
    To copy to clipboard, switch view to plain text mode 

    But When I ran my code and debugged it, there was some problem in converting data to image.

    I think converting unsigned char* to QPixmap like following code is right, but it doesn't work well and also with Format_RGB888, Index8, etc.

    (unsigned char* data was made by ffmpeg video.)

    Qt Code:
    1. QPixmap backBuffer = QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step, QImage::Format::Format_RGB888));
    To copy to clipboard, switch view to plain text mode 

    please share your idea!
    thank you!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying Raw data on QLabel

    Which format does the sender use for the pixel data?

    Have you verified that the read int values are correct?

    Btw, you are leaking the image data and you needlessly convert from pixmap to image and back for scaling.

    Cheers,
    _

Similar Threads

  1. Image Not displaying in Qlabel
    By ranjithrajrrr in forum Newbie
    Replies: 8
    Last Post: 28th July 2016, 06:41
  2. geting QLabel text ontop of other QLabel displaying image
    By krystosan in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2013, 17:35
  3. Qtreeview not displaying data (data() is called)
    By mraww in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2013, 20:19
  4. Qlabel not displaying images other than development machine
    By arunkumaraymuo1 in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2012, 14:52
  5. Problem with displaying image using Qlabel
    By deck99 in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 00:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.