From eb648e31122f40482f0a3da377e0b18d233cf964 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Tue, 3 Mar 2020 09:53:23 +0800 Subject: [PATCH] fix: use format() to check if we support such format --- graphicsview.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/graphicsview.cpp b/graphicsview.cpp index 65c477c..adbe5d7 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -39,8 +39,10 @@ void GraphicsView::showFileFromUrl(const QUrl &url, bool doRequestGallery) QImageReader imageReader(filePath); imageReader.setAutoTransform(true); imageReader.setDecideFormatFromContent(true); - QImage::Format imageFormat = imageReader.imageFormat(); - if (imageFormat == QImage::Format_Invalid) { + // Since if the image format / plugin does not support this feature, imageFormat() will returns an invalid format. + // So we cannot use imageFormat() and check if it returns QImage::Format_Invalid to detect if we support the file. + // QImage::Format imageFormat = imageReader.imageFormat(); + if (imageReader.format().isEmpty()) { showText(tr("File is not a valid image")); } else { showImage(QPixmap::fromImageReader(&imageReader));