Skip to content

Commit

Permalink
QMovie: Make sure to pass on QImageReader errors when they occur
Browse files Browse the repository at this point in the history
If a file cannot be opened for some reason (like running out of FDs),
emit the error signal.

Change-Id: I9586dda34b2f2cef73593c6dcb855b29d63c2dbc
Reviewed-by: Gunnar Sletta <[email protected]>
  • Loading branch information
rburchell committed Apr 14, 2017
1 parent 401d9b5 commit 01a4d09
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/gui/image/qmovie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ int QMoviePrivate::speedAdjustedDelay(int delay) const
*/
QFrameInfo QMoviePrivate::infoForFrame(int frameNumber)
{
Q_Q(QMovie);

if (frameNumber < 0)
return QFrameInfo(); // Invalid

Expand Down Expand Up @@ -358,7 +360,8 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber)
reader = new QImageReader(device, format);
else
reader = new QImageReader(absoluteFilePath, format);
(void)reader->canRead(); // Provoke a device->open() call
if (!reader->canRead()) // Provoke a device->open() call
emit q->error(reader->error());
reader->device()->seek(initialDevicePos);
reader->setBackgroundColor(bgColor);
reader->setScaledSize(scaledSize);
Expand Down Expand Up @@ -525,8 +528,20 @@ void QMoviePrivate::_q_loadNextFrame(bool starting)
*/
bool QMoviePrivate::isValid() const
{
return (greatestFrameNumber >= 0) // have we seen valid data
|| reader->canRead(); // or does the reader see valid data
Q_Q(const QMovie);

if (greatestFrameNumber >= 0)
return true; // have we seen valid data
bool canRead = reader->canRead();
if (!canRead) {
// let the consumer know it's broken
//
// ### the const_cast here is ugly, but 'const' of this method is
// technically wrong right now, since it may cause the underlying device
// to open.
emit const_cast<QMovie*>(q)->error(reader->error());
}
return canRead;
}

/*!
Expand Down

0 comments on commit 01a4d09

Please sign in to comment.