PDA

View Full Version : Insert an QImage or an QPixmap into a mySQL database and then get it back



Alienxs
6th August 2006, 05:43
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.:confused:

Alienxs
6th August 2006, 06:01
:confused: 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:confused:

e8johan
6th August 2006, 08:41
I assume that you can get a QByteArray from your BLOB, and this can be used to create a QImage using QImage::loadFromData.

jacek
6th August 2006, 12:01
How about this:
query.bindValue( ..., pixmap );
...
QPixmap pixmap( query.value( ... ).toPixmap() );
AFAIK the image will be stored as PNG.

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

Alienxs
6th August 2006, 23:30
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:cool: :confused:

jacek
6th August 2006, 23:41
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:cool: :confused:
You don't know what QSqlQuery::bindValue() does? How do you construct your queries?

Alienxs
7th August 2006, 21:49
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

jacek
12th August 2006, 15:11
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.