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. Displaying GIF images from database BLOBs
Forum Updated to NodeBB v4.3 + New Features

Displaying GIF images from database BLOBs

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 616 Views 2 Watching
  • 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.
  • T Offline
    T Offline
    Tharoux
    wrote on 2 May 2020, 07:09 last edited by Tharoux 5 Feb 2020, 20:15
    #1

    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;
            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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 May 2020, 07:58 last edited by mrjj 5 Feb 2020, 07:59
      #2

      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.

      T 1 Reply Last reply 2 May 2020, 08:20
      1
      • M mrjj
        2 May 2020, 07:58

        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.

        T Offline
        T Offline
        Tharoux
        wrote on 2 May 2020, 08:20 last edited by
        #3

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 2 May 2020, 08:33 last edited by
          #4

          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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          1/4

          2 May 2020, 07:09

          • Login

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