StupidBeauty
Read times:625Posted at:Mon May 28 02:49:53 2012
- no title specified

转载:解析QT 使用Sqlite存储读取文件

在QT中,要想将大块的数据以BLOB方式存储到SQLITE中去的话,可先将大块数据序列化到一个QByteArray中,再将该QByteArray像其它类型的数据一样bindValue到一个字段中。

http://mobile.51cto.com/symbian-273532.htm

亮点:

bool MyDatabase::StoreFile(QString FileName) { QSqlQuery query(db); QFile File(FileName); if(File.open(QIODevice::ReadOnly)){ QByteArray &tdata = File.readAll(); QByteArray data = qCompress(tdata,9); query.prepare("INSERT INTO files (id,filename,filecontent)" "VALUES(NULL,:filename,:filecontent)"); query.bindValue(":filename", FileName); query.bindValue(":filecontent", data); if(!query.exec()) { qDebug()<<query.lastError(); return false; } } else { return false; } return true; }

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4