Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Image From Memory to QLabel as Pixmap
Qt 6.11 is out! See what's new in the release blog

Image From Memory to QLabel as Pixmap

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R_IrudezuR Offline
    R_IrudezuR Offline
    R_Irudezu
    wrote on last edited by
    #1

    Hi, i have two variables :

    uint8_t jpegData 
    //and 
    uint32_t jpegDataLen
    

    When i want to write a jpeg file under a directory, i am using these two variables that coming from an external DLL. And i got the JPEG file correctly.

    But when i try to show this jpeg data from memory, program getting crashed. Here's what i am doing:

    first try:

    QImage image;
    image.loadFromData((char *)array[i].jpegMugData, array[i].jpegMugDataLen, "JPG");
    ui->imageLabel->setPixmap(QPixmap::fromImage(image));
    

    second try:

    QBuffer buffer;
    QDataStream in(&buffer);
    QImage image;
    
    buffer.setData((char*)array[i].jpegMugData, array[i].jpegMugDataLen);
    buffer.open(QBuffer::ReadOnly);
    in >> image;
    ui->imageLabel->setPixmap(QPixmap::fromImage(image));
    

    both ways causes to program crash. Like i said when i used these two variables to write jpeg file under a directory there is no problem. What should i do? What am i missing?

    Keizoku wa chikaranari.

    VRoninV 1 Reply Last reply
    0
    • R_IrudezuR R_Irudezu

      Hi, i have two variables :

      uint8_t jpegData 
      //and 
      uint32_t jpegDataLen
      

      When i want to write a jpeg file under a directory, i am using these two variables that coming from an external DLL. And i got the JPEG file correctly.

      But when i try to show this jpeg data from memory, program getting crashed. Here's what i am doing:

      first try:

      QImage image;
      image.loadFromData((char *)array[i].jpegMugData, array[i].jpegMugDataLen, "JPG");
      ui->imageLabel->setPixmap(QPixmap::fromImage(image));
      

      second try:

      QBuffer buffer;
      QDataStream in(&buffer);
      QImage image;
      
      buffer.setData((char*)array[i].jpegMugData, array[i].jpegMugDataLen);
      buffer.open(QBuffer::ReadOnly);
      in >> image;
      ui->imageLabel->setPixmap(QPixmap::fromImage(image));
      

      both ways causes to program crash. Like i said when i used these two variables to write jpeg file under a directory there is no problem. What should i do? What am i missing?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @R_Irudezu said in Image From Memory to QLabel as Pixmap:

      uint8_t jpegData

      This is a single byte. If jpegDataLen>1 it's normal for it to crash.
      You need to allocate the buffer beforehand. QByteArray helps in these cases

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      R_IrudezuR 1 Reply Last reply
      3
      • VRoninV VRonin

        @R_Irudezu said in Image From Memory to QLabel as Pixmap:

        uint8_t jpegData

        This is a single byte. If jpegDataLen>1 it's normal for it to crash.
        You need to allocate the buffer beforehand. QByteArray helps in these cases

        R_IrudezuR Offline
        R_IrudezuR Offline
        R_Irudezu
        wrote on last edited by R_Irudezu
        #3

        @VRonin Yes you're right. I did some minor changes on code and it's now being allocating and there is no crash. But still nothing to display over imageLabel. I suppose because of jpg decoding. How to handle it....

        Edit: it's ok now.

        Keizoku wa chikaranari.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved