QImage在读取某些图档的时候会crash

stereoMatching 2013-01-09 03:47:04
在读取一些bmp图档的时候会导致程序崩溃,图档下载
http://www.sendspace.com/file/trqq80


#include <QtCore>
#include <QtGui>

int main(int argc, char *argv[])
{
QString const prefix = "C:/Qt/crash_pictures/";
QStringList name(QStringList() << "rgb32-111110.bmp" << "rgb32bf.bmp" << "rgba32.bmp"<< "badheadersize.bmp"<<"badpalettesize.bmp");

for(int i = 0; i != name.size(); ++i){
qDebug() << name[i];
QImage read(prefix + name[i]); //crash at here
qDebug() << read.isNull(); //can't reach this line
qDebug() << read.format();
}

return 0;
}


测试环境
Qt版本
Qt4.8, compiler 是 mingw4.6.2, 32bits
Qt5.0, compiler 是 msvc2010 32bits

OS : win7 64bits

这是Qt的bug吗?或者我的使用方法有错?
有何方法可以避免?
只是读不到资料没有关系
会导致程序崩溃则很麻烦
虽然这种图档不常看到
但是我总不能寄希望与侥幸
...全文
1133 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
stereoMatching 2013-02-06
  • 打赏
  • 举报
回复
确定是bug,已经回报到Qt的bug trace上
stereoMatching 2013-01-11
  • 打赏
  • 举报
回复
我受到stl的源码影响较深,也常开发一些泛型的算法 我的写法只是很常见的指标运算的变形

for(auto *p = begin; p != end; ++p)
会认为这个loop会陷入死循环,我在msdn已经被人问过两次了 来讲解一下loop的基本知识 for(int i = 0; i != 5; ++i) int i = 0; //初始条件 i != 5; //终止条件 ++i//没达到终止条件时每一个循环会对i做的事情 所以这个loop代表的是i从0开始计数,当i不等于5的时候,会不停的加1 所以i的变化是0, 1, 2, 3, 4----出现5的时候就会跳出loop 因为i == 5,达到了终止条件 for(int i = 0; i < 5; ++i) 这个loop代表的是i从0开始计数,当i小于5的时候,会不停的加1 所以i的变化是0, 1, 2, 3, 4----出现5的时候就会跳出loop 因为i已经不再小于5 会崩溃的是这三张 "rgb32-111110.bmp","rgb32bf.bmp","rgba32.bmp" 其他图可以不用试
  • 打赏
  • 举报
回复

单步运行没问题 Qt4.7 + VC2008
  • 打赏
  • 举报
回复
单步调试 看看i值的变化
stereoMatching 2013-01-11
  • 打赏
  • 举报
回复
引用 15 楼 marsz1990 的回复:
你这程序是死循环吧。。。
不是死循环,你试一下就知道了
MarsZ 2013-01-11
  • 打赏
  • 举报
回复
引用 1 楼 stereoMatching 的回复:
删减没问题的图档http://www.sendspace.com/file/ureh9l 程式也简化一下 C/C++ code?1234567891011121314151617#include <QtCore>#include <QtGui> int main(int argc, char *argv[]){ QString const prefix = ……
你这程序是死循环吧。。。
stereoMatching 2013-01-10
  • 打赏
  • 举报
回复
更正,是4.8.4
stereoMatching 2013-01-10
  • 打赏
  • 举报
回复
引用 10 楼 openXMPP 的回复:
什么开发平台? 这个地方可能抛出的不是C++的异常,而是结构化异常
Qt版本 Qt4.8, compiler 是 mingw4.6.2, 32bits--crash Qt5.0, compiler 是 msvc2010 32bits--一样会crash OS : win7 64bits 由于有跨平台的需要,编译器是以mingw为主
乔巴好萌 2013-01-10
  • 打赏
  • 举报
回复
引用 9 楼 stereoMatching 的回复:
引用 8 楼 openXMPP 的回复:前面不是有load函数吗 read前先检查下阿 任何函数调用都可能抛出异常 包括stl 你觉得stl就是一个完备的不回抛出异常的 问题是使用者一定要知悉问题所在 如果qt 有异常 你完全可以catch掉阿 …… 我之前在阅读Qt的时候就问过为何Qt完全没有提到哪个function会抛出什么exception? 答案是……
什么开发平台? 这个地方可能抛出的不是C++的异常,而是结构化异常
stereoMatching 2013-01-10
  • 打赏
  • 举报
回复
引用 8 楼 openXMPP 的回复:
前面不是有load函数吗 read前先检查下阿 任何函数调用都可能抛出异常 包括stl 你觉得stl就是一个完备的不回抛出异常的 问题是使用者一定要知悉问题所在 如果qt 有异常 你完全可以catch掉阿 ……
我之前在阅读Qt的时候就问过为何Qt完全没有提到哪个function会抛出什么exception? 答案是Qt为了提高embedded的兼容性,舍弃了exception 加上catch后还是崩溃

int main(int argc, char *argv[])
{    
    QString const prefix = "C:/Qt/crash_pictures/";
    QStringList name(QStringList() << "rgb32-111110.bmp" << "rgb32bf.bmp" << "rgba32.bmp");

    QImage img;
    try{
        for(int i = 0; i != name.size(); ++i){
            qDebug() << name[i];
            qDebug() << img.load(prefix + name[i]);        
        }
    }catch(...){
        qDebug() << "weird bug";
    }

    return 0;
}
乔巴好萌 2013-01-10
  • 打赏
  • 举报
回复
引用 7 楼 stereoMatching 的回复:
引用 5 楼 openXMPP 的回复:引用 4 楼 stereoMatching 的回复:引用 3 楼 jdwx1 的回复:Qt的image可能兼容的格式不是很全,以前在XP上用图片查看器保存的png,在Qt里就打不开。 打不开无所谓,但是不能crash Qt不是专门做图像处理的库,我不奢求他能处理所有的图 引用 2 楼 openXMPP 的回复:bool Q……
前面不是有load函数吗 read前先检查下阿 任何函数调用都可能抛出异常 包括stl 你觉得stl就是一个完备的不回抛出异常的 问题是使用者一定要知悉问题所在 如果qt 有异常 你完全可以catch掉阿
stereoMatching 2013-01-10
  • 打赏
  • 举报
回复
我是否该把这个当成bug并提交到Qt的bug tracker上?
jdwx 2013-01-10
  • 打赏
  • 举报
回复
经测试那几个图片确实不错,程序立即死翘翘。
stereoMatching 2013-01-09
  • 打赏
  • 举报
回复
引用 5 楼 openXMPP 的回复:
引用 4 楼 stereoMatching 的回复:引用 3 楼 jdwx1 的回复:Qt的image可能兼容的格式不是很全,以前在XP上用图片查看器保存的png,在Qt里就打不开。 打不开无所谓,但是不能crash Qt不是专门做图像处理的库,我不奢求他能处理所有的图 引用 2 楼 openXMPP 的回复:bool QImage::load ( const ……
这个测试想知道的就是当图有问题的时候 Qt会如何处理?会不会crash? crash的话客户十之八九不会认为是自己的图有问题 他们会直接拨客服投诉你的软体有问题 我有用openCV2.4.3做测试 有些有问题的图也会导致openCV crash 但我又不能赌我的客户每个都不会遇上有问题的图
乔巴好萌 2013-01-09
  • 打赏
  • 举报
回复
http://lhbyron.bokee.com/652956.html 这个是有关Bmp头的说明 事实上 qt只是提供了一个标准的bmp的解析的快捷方法 和Phonon一样 只是很快捷 但不完备
乔巴好萌 2013-01-09
  • 打赏
  • 举报
回复
引用 4 楼 stereoMatching 的回复:
引用 3 楼 jdwx1 的回复:Qt的image可能兼容的格式不是很全,以前在XP上用图片查看器保存的png,在Qt里就打不开。 打不开无所谓,但是不能crash Qt不是专门做图像处理的库,我不奢求他能处理所有的图 引用 2 楼 openXMPP 的回复:bool QImage::load ( const QString &amp; fileName……
bmp前面是有个header做解析用的 可能是你的bmp的header不对
stereoMatching 2013-01-09
  • 打赏
  • 举报
回复
引用 3 楼 jdwx1 的回复:
Qt的image可能兼容的格式不是很全,以前在XP上用图片查看器保存的png,在Qt里就打不开。
打不开无所谓,但是不能crash Qt不是专门做图像处理的库,我不奢求他能处理所有的图
引用 2 楼 openXMPP 的回复:
bool QImage::load ( const QString & fileName, const char * format = 0 ) Loads an image from the file with the given fileName. Returns true if the image was successfully loaded; other……
那些bmp是特地设计成那个样子的 我原本的预期是打不开会在我呼叫 isNull时回传true,结果却是直接crash
jdwx 2013-01-09
  • 打赏
  • 举报
回复
Qt的image可能兼容的格式不是很全,以前在XP上用图片查看器保存的png,在Qt里就打不开。
乔巴好萌 2013-01-09
  • 打赏
  • 举报
回复
bool QImage::load ( const QString & fileName, const char * format = 0 ) Loads an image from the file with the given fileName. Returns true if the image was successfully loaded; otherwise returns false. The loader attempts to read the image using the specified format, e.g., PNG or JPG. If format is not specified (which is the default), the loader probes the file for a header to guess the file format. The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable. 你的bmp的header应该有问题 导致qt crash 或者分辨率吵过了qt的解析范围 想做bmp或image的解析 建议用别的库
stereoMatching 2013-01-09
  • 打赏
  • 举报
回复
删减没问题的图档http://www.sendspace.com/file/ureh9l 程式也简化一下

#include <QtCore>
#include <QtGui>

int main(int argc, char *argv[])
{
    QString const prefix = "C:/Qt/crash_pictures/";
    QStringList name(QStringList() << "rgb32-111110.bmp" << "rgb32bf.bmp" << "rgba32.bmp");

    for(int i = 0; i != name.size(); ++i){
        qDebug() << name[i];
        QImage read(prefix + name[i]);
        qDebug() << read.isNull();
        qDebug() << read.format();
    }

    return 0;
}

16,824

社区成员

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

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