如何在SQLite数据库中保存image数据,sqliteimage
How to Store and Retrieve an Image or File with SQLite
Images or any files can be stored in a database. Here is one way to do it using the following steps:
1. Read the system file into a QByteArray.
2. Store QByteArray as a Binary Large Object in database.
For example :
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) return;
QByteArray byteArray = file.readAll();
QSqlQuery query;
query.prepare("INSERT INTO imgtable (imgdata) VALUES (?)");
query.addBindValue(byteArray);
query.exec();Now, the image/file can be retrieved like any other data
QSqlQuery query("SELECT imgdata FROM imgtable");
query.next();
QByteArray array = query.value(0).toByteArray();Creating a QPixmap from QByteArray :
QPixmap pixmap = QPixmap();
pixmap.loadFromData(array);搬运工http://qt-project.org/wiki/How_to_Store_and_Retrieve_Image_on_SQLite
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。