Results 1 to 12 of 12

Thread: QImageReader fails inconsistently with "Unable to read image data".

  1. #1
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QImageReader fails inconsistently with "Unable to read image data".

    I am using the QImageReader to read in all of the images in a directory. However it is sometimes unable to read certain images, even if it has read them successfully in the past. The error message is "Unable to read image data". Once there is an error on one file in a directory there tends to be an error on all subsequent files. Can someone explain what is going on? Here is my code:

    Qt Code:
    1. QStringList filters;
    2. foreach (QByteArray format, QImageReader::supportedImageFormats())
    3. filters += "*." + format;
    4. dir.setSorting(QDir::Time | QDir::Reversed);
    5.  
    6. foreach (QFileInfo fileInfo, dir.entryInfoList(filters, QDir::Files))
    7. {
    8. QString filename = fileInfo.fileName();
    9. QString pathname = fileInfo.absoluteFilePath();
    10.  
    11. if (!imageReader)
    12. {
    13. imageReader = new QImageReader(pathname);
    14. }
    15. else
    16. {
    17. imageReader->setFileName(pathname);
    18. }
    19. QImage image = imageReader->read();
    20. if (!image.isNull())
    21. {
    22. Image* myImage = new Image(image);
    23. myImage->s_pathname(pathname);
    24. myImage->s_timestamp (fileInfo.lastModified());
    25. QList<Image *> *imglist = g_imageList();
    26. imglist->append(myImage);
    27. }
    28. else
    29. {
    30. /*
    31. ** Sometimes get the error "Unable to read image data" which is the
    32. ** "InvalidDataError". But it is inconsistent. The same file is
    33. ** successfully read on other occasions.
    34. ** When it fails with one file tends to fail with all other files from that
    35. ** directory. (filename is always ok).
    36. */
    37. QString errstr = imageReader->errorString();
    38. QString path = imageReader->fileName();
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    It seems like a resouce problem, maybe with not enough RAM available? Or some system policy?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    Possibly related... If imagelist is NULL (line 11) then you allocate one (13) but don't set the file name before trying to read at line 19.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    I think constructor at line 13 takes file name as argument.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    Looking at the code again, the first thing I'd do is to get rid of all those unnecessary pointers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    Oh yes, my bad.

  7. #7
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    It does appear to be a resource issue. I am going to try scaling the QImages after I read them, deleting the larger QImage and saving the scaled image and see if that resolves the problem.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    QImageReader has the capability of reading the images already scaled down, at least for some formats.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    mlr (20th June 2011)

  10. #9
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    The issue is resolved. After reading in the image with the QImageReader I scale it to make it the dimensions I will draw it at and delete the original image. The resource issue no longer occurs in this situation and all of the images get drawn. But the performance is very slow where there are 100s of large images (4288 x 2848) so I want to see if I can just read in the thumbnail to begin with and not have to read in all of those large images.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    Read what I said again -- you can load the image already scaled. Performance will be much better then. See QImageReader::setScaledSize().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    Reading the image in scaled down form performs better than scaling down after reading.

  13. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QImageReader fails inconsistently with "Unable to read image data".

    A 4288 x 2848 image with 24-bits per pixel is ~36MB per image uncompressed in memory (48MB if there's an alpha channel). Loading lots of these is certainly a rapid way to consume memory.

Similar Threads

  1. "Unable to read symbols" Problem
    By weaver4 in forum Newbie
    Replies: 10
    Last Post: 20th December 2012, 22:36
  2. Replies: 4
    Last Post: 2nd June 2012, 07:04
  3. why "Unable to read image data"
    By zarelaky in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 21st December 2010, 00:47
  4. QTcpSocket read duplicate data, but only on "bad channel"
    By creatron in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2010, 19:17
  5. Replies: 1
    Last Post: 7th April 2010, 21:46

Tags for this Thread

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.