I have a QByteArray and this one holds an image.
How can I display the image from my QByteArray in a QLabel ?
I have a QByteArray and this one holds an image.
How can I display the image from my QByteArray in a QLabel ?
Qt Code:
QPixmap image; QByteArray ba; image.loadFromData(ba);To copy to clipboard, switch view to plain text mode
This is my code, and note that the "image.png" is an image located in the same folder as the source code:
Qt Code:
int main(int argc, char *argv[]) { widget->setFixedSize(500, 500); widget->show(); label->setGeometry(10, 10, 480, 480); label->show(); *temp = file->readAll(); pix->loadFromData(*temp); label->setPixmap(*pix); return application->exec(); }To copy to clipboard, switch view to plain text mode
This gives me a message saying:
QPixmap::convertFromImage: Cannot convert a null image
What am I missing ?
Thanks for the help. I found the error which was that I was not opening the file
Why don't you just load the picture directly from a file?
I don't load the picture from the file, because the picture is not located in the local hard disk, so I need to pass this picture from one computer to another.
Is there any other solution ?
how about displaying the image contained in the QByteArray in a QTextBrowser.
Is it possible, how ?
Make a pixmap out of it like shown in previous posts and load it into the text browser from a document that will reference it (using img src="xxx"). Just make sure this pixmap is available to the browser -- read the docs to see how it's done.Originally Posted by probine
Bookmarks