如何在QT中将图像保存在mysql数据库中? [英] How to save the image in mysql database in QT?

查看:493
本文介绍了如何在QT中将图像保存在mysql数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在QT中将映像保存在mysql数据库中?我正在使用以下代码:
我犯了什么错误,请给我建议.


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();

推荐答案

query.bindValue(:image",(QVariant)buf.data());是错误.

确保已加载图像的所有位均已写入数据库中.为什么不将文件复制到某个存储并引用该路径.这样可以加快整个过程并简化维护.
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.


这篇关于如何在QT中将图像保存在mysql数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆