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 ?
if (!finfo.exists() || !finfo.isFile()) {
img
= QDir::currentPath() + QDir::separator() + "skins/no_pic.png";
}
if (f.
open(QFile::ReadOnly)) { f.close();
if (ba.size() != finfo.size()) {
qDebug() << "read file error ! size:" << finfo.size() << " read: " << ba.size() << "\r\n" ;
}
int retryTimes(1);
do {
b.setBuffer(&ba);
bool bR = ir.read(&im);
if (!bR || im.isNull()) {
qDebug() << ir.errorString() << "\r\n";
} else {
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;
}
}
} while (--retryTimes);
} else {
qDebug() << "open file failed " << f.errorString() << "\r\n";
}
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";
}
To copy to clipboard, switch view to plain text mode
Bookmarks