Results 1 to 8 of 8

Thread: Insert an QImage or an QPixmap into a mySQL database and then get it back

  1. #1
    Join Date
    Aug 2006
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Loading a custom image into a QPixmap

    hi i dont know if this is the right place to my question but i will try anyway, im traying to insert a QImage or a QPixmap into a MySQL database into a blob field but i try several ways and nothing i tryed to pass the image to a QBytearray an then save it into my DB and nothing happend i would like to know if anyone of you al ready did it and could tell my how or at lease send me a tutorial about how to do this, because it's a very important thing to me.

  2. #2
    Join Date
    Aug 2006
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Insert an QImage or an QPixmap into a mySQL database and then get it back

    hello i create this Thread because im trying to develop an application wich will comunicate with a mysql DB wich one contain several tables and one of this tables have an blob field to save images files, not the route to the image just the image, and i looked arround the internet and didnt found to much, that´s why im here i would like to know if anyone of you allready did this save an image into a blob field from a mysql DB and get it back and then show it on a QLabel using QT.

    I could get the URL and then load the image on a QLabel, but that´s not the way i need, because if the image is erased from the local directory it should remain into the DB inside a table.

    Do you know what i mean???

    Please HELLLLPPP MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

  3. #3
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert an QImage or an QPixmap into a mySQL database and then get it back

    I assume that you can get a QByteArray from your BLOB, and this can be used to create a QImage using QImage::loadFromData.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading a custom image into a QPixmap

    How about this:
    Qt Code:
    1. query.bindValue( ..., pixmap );
    2. ...
    3. QPixmap pixmap( query.value( ... ).toPixmap() );
    To copy to clipboard, switch view to plain text mode 
    AFAIK the image will be stored as PNG.

    PS. Please, don't post the same question twice.

  5. #5
    Join Date
    Aug 2006
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Insert an QImage or an QPixmap into a mySQL database and then get it back

    I all ready tryed to convert the QImage or the QPixmap into a QByteArray and then save it into a BLOB field but it didnt work cause i checked the table and it was empty, but if you all ready did it just tell me please and i will check about what i did wrong.

    And Jacek please could you talk to me better about your method, to try it and see what happend, to tell you then how was it PLEASE

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert an QImage or an QPixmap into a mySQL database and then get it back

    Quote Originally Posted by Alienxs
    And Jacek please could you talk to me better about your method, to try it and see what happend, to tell you then how was it PLEASE
    You don't know what QSqlQuery::bindValue() does? How do you construct your queries?

  7. #7
    Join Date
    Aug 2006
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Insert an QImage or an QPixmap into a mySQL database and then get it back

    jacek hi, look the thing is i could insert data into my database but now im trying to develop an application to manage a clinical database you know and they asked me to give them the posibility to save image in the database, so what i did first was to save the URL belong to the image into the database on a blob field from a table, but i work out that its not efficient because anyone could acces to the image, so what i want to do it's get the image on any format i mean *.jpg *.bmp *.any_image_format_support and then save the image into my DB this allow me to trash the image from my hard disk but it still will remain into my DB you know.
    The problem comes when i try to save the image, and why because through QSqlQuery i just can insert QString but the image its QImage or QPixmap and that's not a Qstring so i have to process the image file to save it into my table and i tried to convert the image to a QByteArray and it didnt work so i tried to create a QFile save the image contents there and get the QFile contents on a QString and then save it into my DB on a blob field from a table buttttt it looks like it didnt either, so if you or anyone could do a thing like Save an image into MySQL DB.
    P.S: i tried to save the image on a QBuffer and then save the QBuffer image on a QString to save it into my DB it seems to work but i could get it back.

    PLEASE HELP MEEEEEEEE

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert an QImage or an QPixmap into a mySQL database and then get it back

    Quote Originally Posted by Alienxs
    The problem comes when i try to save the image, and why because through QSqlQuery i just can insert QString
    You can insert any type that QVariant can represent --- that's what QSqlQuery::bindValue() is for.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.