From d9df8c3f474b128b1631f1ff58ec2026ab21272d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 30 Mar 2018 07:57:30 +0200 Subject: Debug: Error reporting for SHashedImage loading Overwrite QImage::load() in SHashedImage so that we can perform better error reporting. Signed-off-by: Berthold Stoeger --- core/imagedownloader.cpp | 11 +++++++++++ core/imagedownloader.h | 1 + 2 files changed, 12 insertions(+) (limited to 'core') diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index aaab9a434..8610d3454 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -6,6 +6,7 @@ #include "imagedownloader.h" #include #include +#include #include @@ -102,6 +103,16 @@ static void loadPicture(struct picture *picture, bool fromHash) download.load(fromHash); } +// Overwrite QImage::load() so that we can perform better error reporting. +bool SHashedImage::load(const QString &fileName, const char *format) +{ + QImageReader reader(fileName, format); + static_cast(*this) = reader.read(); + if (isNull()) + qInfo() << "Error loading image" << fileName << (int)reader.error() << reader.errorString(); + return !isNull(); +} + SHashedImage::SHashedImage(struct picture *picture) : QImage() { QUrl url = QUrl::fromUserInput(localFilePath(QString(picture->filename))); diff --git a/core/imagedownloader.h b/core/imagedownloader.h index be196aaef..dc42aee4d 100644 --- a/core/imagedownloader.h +++ b/core/imagedownloader.h @@ -20,6 +20,7 @@ private: }; class SHashedImage : public QImage { + bool load(const QString &fileName, const char *format=nullptr); public: SHashedImage(struct picture *picture); }; -- cgit v1.2.3-70-g09d2