PDA

View Full Version : Load image from QNetworkReply incorrectly



tqlong
1st July 2010, 16:51
I tried to load an image from this Latex to image website

http://mathtran.org/cgi-bin/mathtran?D=3;tex=1%2B2

to get an PNG image of 1+2. However, what I get is just the image of the number 1.

Here is my code


void FTransUI::fetchDone(QNetworkReply* reply) {
QImage image;
if (reply->error() == QNetworkReply::NoError) {
cout << "bytes = " << reply->bytesAvailable() << endl; //
image.load(reply, 0);
cout << "After load bytes = " << reply->bytesAvailable() << endl;
cout << "Image = " << image.width() << " x " << image.height() << endl;
if (!image.isNull()) {
QPixmap pixmap = QPixmap::fromImage(image);
imgLabel->setPixmap(pixmap);
}
else
QMessageBox::information(this, "Error", tr("NULL IMG"));
}
else {
QMessageBox::information(this, "Error", tr("Cannot access"));
}
reply->deleteLater();
//delete reply;
}


Previous to image.load, bytesAvailable = 366
After load, bytesAvailable = 0 (which is normal after reading all data of an image)
However, the size of the image is 10 x 15 (the width is wrong, it should be bigger than 10 for image of 1+2).
I have no problem like this when I use QHttp (which is now obsolete).
Thanks for your help.