
Originally Posted by
seneca
I guess you need to create the QDataStream after filling str2recover.
Reason: At the time you currently create the datasteam in your sample, the byte array is empty and the stream will have status ReadPastEnd instead of Ok
I did that but still no luck,BTW I noticed that the way I save the picture in the database takes much more space than the image size itself,I changed it to following and the size of the blob is the same as the picture now
QImage pix
("c:/parva.jpg",
"JPEG");
pix.save(&buffer,"JPEG");
insertPicCom.bindValue(0,str2Store);
insertPicCom.exec();
QByteArray str2Store;
QImage pix("c:/parva.jpg","JPEG");
QBuffer buffer(&str2Store);
buffer.open(QIODevice::WriteOnly);
pix.save(&buffer,"JPEG");
QSqlQuery insertPicCom(QString("insert into pix values(?)"));
insertPicCom.bindValue(0,str2Store);
insertPicCom.exec();
To copy to clipboard, switch view to plain text mode
but I still have problem how to reverse the process and retrieve the picture from database into a QImage,Any ideas?
PS:
I noticed that the size of QByteArray I save in database is 3056 bytes but when I retrieve it from database and put it in another QByteArray it's 5464 bytes which means sth like a header or .. has been added to it,how can I turn it to the original QByteArray?
Bookmarks