Hello all... I've got an application in which I want to be able to store a few icons in a database (so all clients can use the same icon set, regardless of location). I thought I had worked out a means of accomplishing this, but it appears not... I only get a corrupted image on restore. Basically, I convert the QIcon to a QPixmap, which I then convert to a QImage, which I then call the bits function on, which I then pass to the QByteArray constructor (after casting to a const char *).
Pretty convoluted, and I suspect that I may have misread the docs at some point along the way. Here's what I'm doing specifically in code:
Recording an icon:
q.prepare("UPDATE discs SET typeicon=:icon WHERE library=:id AND slot=:slot");
QImage image
(m_typeIcon.
pixmap(QSize(32,
32)).
toImage());
QByteArray ba
((const char *)image.
bits(), image.
numBytes());
q.bindValue(":icon", ba);
q.prepare("UPDATE discs SET typeicon=:icon WHERE library=:id AND slot=:slot");
QImage image(m_typeIcon.pixmap(QSize(32, 32)).toImage());
QByteArray ba((const char *)image.bits(), image.numBytes());
q.bindValue(":icon", ba);
To copy to clipboard, switch view to plain text mode
where q is a QSqlQuery object and m_typeIcon is a QIcon object.
Reading an icon:
m_typeIcon
= QIcon(QPixmap::fromImage(QImage((const uchar
*)q.
value(3).
toByteArray().
constData(),
32,
32,
QImage::Format_RGB32)));
m_typeIcon = QIcon(QPixmap::fromImage(QImage((const uchar *)q.value(3).toByteArray().constData(), 32, 32, QImage::Format_RGB32)));
To copy to clipboard, switch view to plain text mode
Again, q is a QSqlQuery object, and the icon is in column 3 of a select statement.
The data itself is stored in the database as a varbinary(32000).
Bookmarks