PDA

View Full Version : why "Unable to read image data"



zarelaky
19th December 2010, 11:45
I use the code below loading png image frequent on ce5 device , at the begin every thing ok, a hour later, i get the error message "unable to read image data", somebody can help me ?


QImage im;
QString img = m_imgs.last();
QFileInfo finfo(img);
if (!finfo.exists() || !finfo.isFile()) {
img = QDir::currentPath() + QDir::separator() + "skins/no_pic.png";
}

QFile f(img);
if (f.open(QFile::ReadOnly)) {
QByteArray ba = f.readAll();
f.close();
if (ba.size() != finfo.size()) {
qDebug() << "read file error ! size:" << finfo.size() << " read: " << ba.size() << "\r\n" ;
}
int retryTimes(1);
do {
QBuffer b;
b.setBuffer(&ba);
b.open(QIODevice::ReadOnly);
QImageReader ir(&b);
bool bR = ir.read(&im);
if (!bR || im.isNull()) {
qDebug() << ir.errorString() << "\r\n";
} else {
QPainter p(m_px);
p.drawImage(0,0,im);
if (m_px->isNull()) {
qDebug() << QString("convert to pixmap failed ! %1").arg(img) << "\r\n";
}
else {
m_imgs.clear();
break;
}
}
QPixmapCache::clear();
} while (--retryTimes);

} else {
qDebug() << "open file failed " << f.errorString() << "\r\n";
}

zarelaky
21st December 2010, 00:47
more:
I run the program on the device, 6 hours later, It crashed, the debug windows show me the memory not enough, null image return.