Details
-
Suggestion
-
Resolution: Done
-
Not Evaluated
-
None
-
5.12
-
None
Description
When I try to load a corrupted jpeg file using QImage, QT prints the warnings through the MessageHandler. It makes it hard to catch the message in the caller's code. Also, it can pollute the console or the screen (since I redirect these warnings to a QDialog). Unfortunately there is no way to test the JPEG before opening or mute these messages.
I think the code responsible for this issue is located in qjpeghandler.cpp: my_error_exit().
One workaround would be to filter these messages in a custom MessageHandler and save them. This approach is detailed in:
https://stackoverflow.com/a/33452293/6050364
But it also has its own issues when doing it concurrently. Also, the developer needs to be aware of all the possible messages that need to be filtered.
I think QImage::loadFromData() should return the error text in a new argument, raise an exception, or save it temporarily to be accessed using another function, similarly as in ifstream.