I am using the following code:
I am reading the jpeg image in Qbytearray; But while saving to database, the image size is doubled and while retrieving from database, the file is being corrupted. How to read the image properly??

Qt Code:
  1. QByteArray buf=NULL;
  2. originalPixmap =QPixmap();
  3. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
  4. QString strfname;
  5. strfname.sprintf("%d",c);
  6. originalPixmap.save("C:\\Program Files\\image"+strfname+".jpeg","jpeg");
  7. c++;
  8. char Data;
  9. QFile file("C:\\Program Files\\image"+strfname+".jpeg");
  10. file.open(QIODevice::ReadOnly);
  11. int len=file.size();
  12. //buf=file.read(len);
  13. buf=file.readAll();
  14. file.close();
  15. file.remove();
  16. QSqlQuery query;
  17. query.exec("INSERT INTO log (grab_date, ip_address, image,logged_user) "
  18. "VALUES (?,?,?,?)");
  19. query.bindValue(0,dd);
  20. query.bindValue(1,address);
  21. query.bindValue(2,buf.toBase64());
  22. query.bindValue (3,hostname);
  23. bool qry=query.exec();
To copy to clipboard, switch view to plain text mode