Important: Please read the Qt Code of Conduct -

Displaying GIF images from database BLOBs

  • EDIT:

    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());

    fixed it.

    Thanks to @mrjj and @Christian-Ehrlicher for helping me, even though I'm such a noob :>

    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;
            //Above results in null QPixmap.
    //Create label for the image.
            QLabel *tempImgLabel = new QLabel();
            //This will be a 0x0 label because outPixmap is null.

    Thanks for help in advance, noob out.

  • Lifetime Qt Champion

    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.

  • @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?

  • Lifetime Qt Champion

    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.

Log in to reply