Click here to Skip to main content
11,637,662 members (91,428 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to save the image in mysql database in QT? I am using the following code:
What mistake i am making, Please suggest me..


 originalPixmap =QPixmap();
            originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
            QString strfname;
            strfname.sprintf("%d",c);
            originalPixmap.save("D:\\image"+strfname+".jpeg","jpeg");
            c++;
            char Data;
            QFile file("D:\\image"+strfname+".jpeg");
            file.open(QIODevice::ReadOnly);
            file.seek(0);
            int len=file.size();
            QByteArray buf;
            buf=file.read(len);
            QSqlQuery query;
            query.prepare("INSERT INTO log (id,grab_date, ip_address, image,logged_user) "
                          "VALUES (:id, :grab_date, :ip_address, :image,  :logged_user)");
            query.bindValue(":id",400);
            query.bindValue(":grab_date",(QVariant)'2011-04-26 15:55:09');
            query.bindValue(":ip_address",(QVariant)'172.16.0.51');
            query.bindValue(":image",(QVariant)buf.data());
            query.bindValue ( ":logged_user",(QVariant) hostname);
            bool qry=query.exec();
Posted 16-Jul-11 2:59am
Comments
digimanus at 18-Jul-11 4:34am
   
which error you receive?
Gokulnath007 at 18-Jul-11 5:37am
   
Nothing is updated in the database.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

query.bindValue(":image",(QVariant)buf.data()); is the bug.

Ensure that all bits of the loaded image were written in the database. Why not copy the file to some store and referring that path. It speeds up the whole process and makes maintenance easier.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 380
1 Sergey Alexandrovich Kryukov 309
2 stibee 308
3 OriginalGriff 230
4 sasanka sekhar panda 190
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,763
2 Mika Wendelius 6,999
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100