Re: Save images to database
If you want Qt to decode and/or encode it, the format should be on this list.
If you just need the data from an image file, QFile::readAll() should be enough. If you want to encode the image in memory, you need the following:
Code:
writer.write(image);
To decode:
I'm assuming you know how to insert the QByteArray into the database and get it out, but If you any clarification, just ask.
Re: Save images to database
It should be possible to convert between QVariant and QImage with a single line of code.
Re: Save images to database
Thanks init2null. I actually did it a similar way. I used QFile::readAll() and stored that into the database. Then used QImage::loadFromData() to put into memory.
Now I want to view it and I want to display it with a few lineEdits and a couple of buttons in a QMainWindow. Unfortunately the widget I want to display it on is not giving me back it's proper size in order to scale the image. Do you know why it would do that?
Re: Save images to database
Quote:
Originally Posted by jnk5y
Thanks init2null. I actually did it a similar way. I used QFile::readAll() and stored that into the database. Then used QImage::loadFromData() to put into memory.
Now I want to view it and I want to display it with a few lineEdits and a couple of buttons in a QMainWindow. Unfortunately the widget I want to display it on is not giving me back it's proper size in order to scale the image. Do you know why it would do that?
Widgets do not always correctly report their sizes until just before they are shown (particularly when they are used in layouts). Defer your code until the showEvent() to get accurate widget sizes.