Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Image From Memory to QLabel as Pixmap
R_Irudezu last edited by
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:
QImage image; image.loadFromData((char *)array[i].jpegMugData, array[i].jpegMugDataLen, "JPG"); ui->imageLabel->setPixmap(QPixmap::fromImage(image));
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?
VRonin last edited by
This is a single byte. If
jpegDataLen>1 it's normal for it to crash.
You need to allocate the buffer beforehand.
QByteArrayhelps in these cases
R_Irudezu last edited by R_Irudezu
@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.