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!
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!