Results 1 to 2 of 2

Thread: why "Unable to read image data"

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default why "Unable to read image data"

    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 ?

    Qt Code:
    1. QImage im;
    2. QString img = m_imgs.last();
    3. QFileInfo finfo(img);
    4. if (!finfo.exists() || !finfo.isFile()) {
    5. img = QDir::currentPath() + QDir::separator() + "skins/no_pic.png";
    6. }
    7.  
    8. QFile f(img);
    9. if (f.open(QFile::ReadOnly)) {
    10. QByteArray ba = f.readAll();
    11. f.close();
    12. if (ba.size() != finfo.size()) {
    13. qDebug() << "read file error ! size:" << finfo.size() << " read: " << ba.size() << "\r\n" ;
    14. }
    15. int retryTimes(1);
    16. do {
    17. b.setBuffer(&ba);
    18. b.open(QIODevice::ReadOnly);
    19. QImageReader ir(&b);
    20. bool bR = ir.read(&im);
    21. if (!bR || im.isNull()) {
    22. qDebug() << ir.errorString() << "\r\n";
    23. } else {
    24. QPainter p(m_px);
    25. p.drawImage(0,0,im);
    26. if (m_px->isNull()) {
    27. qDebug() << QString("convert to pixmap failed ! %1").arg(img) << "\r\n";
    28. }
    29. else {
    30. m_imgs.clear();
    31. break;
    32. }
    33. }
    34. QPixmapCache::clear();
    35. } while (--retryTimes);
    36.  
    37. } else {
    38. qDebug() << "open file failed " << f.errorString() << "\r\n";
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 20th December 2010 at 09:26. Reason: code tags

  2. #2
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: why "Unable to read image data"

    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.

Similar Threads

  1. Replies: 4
    Last Post: 2nd June 2012, 07:04
  2. QTcpSocket read duplicate data, but only on "bad channel"
    By creatron in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2010, 19:17
  3. Replies: 9
    Last Post: 20th May 2010, 09:55
  4. Replies: 1
    Last Post: 7th April 2010, 21:46
  5. Replies: 3
    Last Post: 25th August 2009, 13:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.