PDA

View Full Version : QByteArray to QPixmap



woodtluk
26th July 2010, 18:18
Hello everybody

I've a network request that returns a jpeg image. But I get the data as raw QByteArray. How can I convert the QByteArray into a QPixmap?

The requestFinished(QNetworkReply *pReply) slot shown below is connected to the signal void finished(QNetworkReply *) of QNetworkManager.


void NetworkManagement::requestFinished(QNetworkReply *pReply) {
if (!pReply->error()) {

// I need the pixmap to show it in a list view (decoration role)
QPixmap pixmap(pReply->readAll());

// I try to save the pixmap as a jpg file to the disk.
bool result = pixmap.save("test.jpg", "jpg");
// This fails, Don't know why.
Q_ASSERT(result);
}
}

Any advice?

Thanks!

franz
26th July 2010, 18:37
You probably need to use QPixmap::loadFromData() (http://doc.trolltech.com/latest/qpixmap.html#loadFromData-3).

woodtluk
27th July 2010, 12:51
Thanks It worked this way!