Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Displaying GIF images from database BLOBs
Tharoux last edited by Tharoux
I got my engineering brother to look this and he found a solution.
My old SQL query was
SELECT image FROM databaseTable;
but that was losing some information for some reason. Changing this query to
SELECT hex(image) FROM databaseTable;
and the QByteArray below to
QByteArray outByteArray = QByteArray::fromHex(SQLquery.value(0).toByteArray());
Hi, I'm rather new to Qt and c++ so please bare with me.
I'm trying to retrieve a bunch of GIF images from SQLite database (they're in BLOB form). I've tried using the example from here but for some reason the
outPixmap.loadFromData( outByteArray );
part always fails, leaving the outPixmap to be a null QPixmap.
Here's the problem part of my code:
//Get image from database BLOB. QByteArray outByteArray = SQLquery.value(0).toByteArray(); QPixmap outPixmap; outPixmap.loadFromData(outByteArray); //Above results in null QPixmap. //Create label for the image. QLabel *tempImgLabel = new QLabel(); tempImgLabel->setPixmap(outPixmap); //This will be a 0x0 label because outPixmap is null.
Thanks for help in advance, noob out.
Hi and welcome to the forums
What did save the gifs blob ?
Unless also done with Qt and ByteArray then
it wont work :)
So its very important how the gif became blobs in the database as the reverse of that has to happen.
Tharoux last edited by
@mrjj Thank you for the answer. I made the database using DB Browser and added the BLOBs that way. So if this isn't going to work, is there a method to retrieve the images from pre-existing database BLOBs?
Please show the complete query code, also you can try to save the QByteArray into a QFile and inspect this to see if it contains the correct data.