请高手分析一下QImageReaderPrivate::initHandler() 返回false的原因

wanghuakl 2013-11-06 09:42:00
/*!
\internal
*/
bool QImageReaderPrivate::initHandler()
{
// check some preconditions
if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
imageReaderError = QImageReader::DeviceError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device"));
return false;
}

// probe the file extension
if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
QList<QByteArray> extensions = QImageReader::supportedImageFormats();
if (!format.isEmpty()) {
// Try the most probable extension first
int currentFormatIndex = extensions.indexOf(format.toLower());
if (currentFormatIndex > 0)
extensions.swap(0, currentFormatIndex);
}

int currentExtension = 0;

QFile *file = static_cast<QFile *>(device);
QString fileName = file->fileName();

do {
file->setFileName(fileName + QLatin1Char('.')
+ QString::fromLatin1(extensions.at(currentExtension++).constData()));
file->open(QIODevice::ReadOnly);
} while (!file->isOpen() && currentExtension < extensions.size());

if (!device->isOpen()) {
imageReaderError = QImageReader::FileNotFoundError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found"));
file->setFileName(fileName); // restore the old file name
return false;
}
}

// assign a handler
if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
imageReaderError = QImageReader::UnsupportedFormatError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
return false;
}
return true;
}


...全文
181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghuakl 2013-11-08
  • 打赏
  • 举报
回复
补充一下,具体问题如下: 我使用QMovie的frameCount()获取GIF文件的帧数,在我自己的机器(win7-64位系统)上得到的帧数正确,在其他很多机器(win7-32位系统)上得到的帧数为-1,不知道为什么,求大家帮忙? 代码如下: m_movie = new QMovie(m_ImagFileName);//m_ImagFileName为完整的gif文件路径 int iFrameCount = m_movie->frameCount();
wanghuakl 2013-11-08
  • 打赏
  • 举报
回复
我使用QMovie的frameCount()获取GIF文件的帧数,在我自己的机器(win7-64位系统)上得到的帧数正确,在其他很多机器(win7-32位系统)上得到的帧数为-1,不知道为什么,求大家帮忙? 代码如下: m_movie = new QMovie(m_ImagFileName);//m_ImagFileName为完整的gif文件路径 int iFrameCount = m_movie->frameCount();
dext 2013-11-07
  • 打赏
  • 举报
回复
设备都打不开,或者没有就绪,当然要返回false了。 最好看看插件之类的装上了没有。
RabinSong 2013-11-07
  • 打赏
  • 举报
回复
朋友,你只有把你的问题写出来,我们才好帮你啊

16,235

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧