I am trying to get create a QIcon object from a website's favicon.ico file. Since this download doesn't necessarily happen on the GUI thread, I cannot use QPixmap, and so far I have had no luck figuring out how to convert from QImage to QIcon without using QPixmap, so I can't use something like QImageReader.
I have gotten the following code to work:
QUrl url("http://www.google.com/favicon.ico");
QNetworkRequest request(url);
QNetworkReply* pReply = manager.get(request);
// ... code to wait for the reply ...
QByteArray bytes(pReply->readAll());
QFile file("C:/favicon.ico");
file.open(QIODevice::WriteOnly);
file.write(bytes);
file.close();
QIcon icon("C:/favicon.ico");
return icon;
However, I want to avoid writing a temporary file. So I tried something like...
QBuffer buffer(&bytes);
buffer.open(QIODevice::ReadOnly);
QDataStream ds(&buffer);
QIcon icon;
ds >> icon;
But that doesn't work.
Does anyone have any suggestions?