HamedMasafi / Nut

Advanced, Powerful and easy to use ORM for Qt
GNU Lesser General Public License v3.0
294 stars 75 forks source link

QByteArray not stored correctly #114

Open yusufmk opened 4 years ago

yusufmk commented 4 years ago

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:

HamedMasafi commented 4 years ago

Hi @yusufmk Thanks for reporting I will check it ASAP

yusufmk commented 3 years ago

Any update on this? pleaaaase...

yusufmk commented 3 years ago

Hi did you get a chance to look at this?

HamedMasafi commented 3 years ago

Hey @yusufmk I will check it within few days Thanks for your patiencion