Nut
Nut copied to clipboard
QByteArray not stored correctly
Hello, I am trying to store an image in a sqlite database. I generate a QByteArray from pixmap. The resultant byte array has 10000 elements in it. Then I create a nut row, set image column, append new row to table and lastly save changes. None of them return any errors. The code I use is given below:
db.open();
QByteArray bArray;
QBuffer buffer(&bArray);
buffer.open(QIODevice::WriteOnly);
ui->lblGelCardImage->pixmap()->save(&buffer, "PNG");
auto newReport = Nut::create<Report>();
newReport->setImage(bArray);
// set other columns as well...
db.tblReports()->append(newReport);
bool ok = db.saveChanges();
BUT, my database doesn't increase in size AND when I try to retrieve the data back, it only returns 10 bytes. The code I use in order to retrieve the image is given below:
db.open();
QByteArray ba = db.tblReports()->query()->first().data()->Image();
Byte array "ba" only has 10 bytes of data in it. It should have contained 10000 bytes of data. What is the problem here? Am I doing something wrong? Every other column is stored and retrieved correctly.
tblReport class has the line below regarding Image field.
NUT_DECLARE_FIELD(QByteArray, Image, Image, setImage)
I used Nut version that you used in OrmTest repo. Actually that is the only version i was able to use after hours of trying. I am kinda newbie to qt.
Development platform:
- OS: ubuntu 18.04
- Qt creator 4.13.0, based on Qt 5.15.0
- Compiler GCC 5.3.1
- Nut commit hash: Commit 6ce50e22 by Jack Lilhammers, 07/07/2020 05:50 PM
- Serializer commit hash: Commit b0194da3 by Miklós Márton, 06/13/2020 12:00 AM
Hi @yusufmk Thanks for reporting I will check it ASAP
Any update on this? pleaaaase...
Hi did you get a chance to look at this?
Hey @yusufmk I will check it within few days Thanks for your patiencion