diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-10-08 16:40:13 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-10 13:24:23 +0200 |
commit | 008e5ba61a68846ad29c65a2fe10b8c19c74f6eb (patch) | |
tree | 59f1bc75adb09b41b862de4145924368529ef95d /src/gui/image/qimage.cpp | |
parent | 34c31cd74cde7a1c36f3603a625fb0d28c259a6e (diff) |
Invalidate old QImage data if load()/loadFromData() has failed
This guarantees one will never get `!img.isNull()` after
load()/loadFromData() has failed, even if the image was
not null before.
Apply the same fix to QPixmap and QPicture.
Change-Id: Ida1ad6a6f0fc830df8e75ada0c163fc2d3360dea
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index bf12dac41d..25999b7d06 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4346,7 +4346,8 @@ QImage QImage::rgbSwapped() const /*! Loads an image from the file with the given \a fileName. Returns true if - the image was successfully loaded; otherwise returns false. + the image was successfully loaded; otherwise invalidates the image + and returns false. The loader attempts to read the image using the specified \a format, e.g., PNG or JPG. If \a format is not specified (which is the default), the @@ -4363,15 +4364,9 @@ QImage QImage::rgbSwapped() const bool QImage::load(const QString &fileName, const char* format) { - if (fileName.isEmpty()) - return false; - QImage image = QImageReader(fileName, format).read(); - if (!image.isNull()) { - operator=(image); - return true; - } - return false; + operator=(image); + return !isNull(); } /*! @@ -4384,11 +4379,8 @@ bool QImage::load(const QString &fileName, const char* format) bool QImage::load(QIODevice* device, const char* format) { QImage image = QImageReader(device, format).read(); - if(!image.isNull()) { - operator=(image); - return true; - } - return false; + operator=(image); + return !isNull(); } /*! @@ -4396,7 +4388,7 @@ bool QImage::load(QIODevice* device, const char* format) Loads an image from the first \a len bytes of the given binary \a data. Returns true if the image was successfully loaded; otherwise - returns false. + invalidates the image and returns false. The loader attempts to read the image using the specified \a format, e.g., PNG or JPG. If \a format is not specified (which is the default), the @@ -4408,11 +4400,8 @@ bool QImage::load(QIODevice* device, const char* format) bool QImage::loadFromData(const uchar *data, int len, const char *format) { QImage image = fromData(data, len, format); - if (!image.isNull()) { - operator=(image); - return true; - } - return false; + operator=(image); + return !isNull(); } /*! |