• 20731阅读
  • 11回复

Qt内存泄露、越界问题!!!求解答,谢谢!!! [复制链接]

上一主题 下一主题
离线liuligang88
 

只看楼主 倒序阅读 楼主  发表于: 2015-12-17
我在Qt的debug模式下调试程序,在多次点击一个按钮功能后,应用程序输出下面这些:

QImage: out of memory, returning null image
QImage: out of memory, returning null image
QImage: out of memory, returning null image
QImage: out of memory, returning null image
QImage: out of memory, returning null image
In file ..\..\include\QtCore/../../src/corelib/global/qglobal.h, line 725: Out of memory
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setCompositionMode: Painter not active
QWidget::repaint: Recursive repaint detected
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setCompositionMode: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setCompositionMode: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setCompositionMode: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.

我不知道是什么原因???是内存越界吗???如果是的话,我该如何操作?Qt上面有查找内存越界的功能吗??
求大神指点一下,不胜感激!!!谢谢!!!
离线stlcours

只看该作者 1楼 发表于: 2015-12-18
提问的智慧:
http://bbs.csdn.net/smart_questions
https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way

代码都不贴出来,哪个神仙能帮你?
离线realfan

只看该作者 2楼 发表于: 2015-12-18
感觉你是在paintEvent()调用了paintEvent(),导致无退出的深层调用,最后资源无法分配 out of memory,是内存不足
离线liuligang88

只看该作者 3楼 发表于: 2015-12-18
回 stlcours 的帖子
stlcours:提问的智慧:
http://bbs.csdn.net/smart_questions
https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way
代码都不贴出来,哪个神仙能帮你? (2015-12-18 05:14) 

首先,非常感谢你的帮助。
不是我不贴代码,是没法贴,公司的电脑都有加密的,付上的工程都是乱码的。
如果复制代码,好几万句的代码。再说这是给公司做个项目,也不能这么做。
我不是想要问具体哪句代码有问题,只是想问这是什么问题,我好针对问题找出问题所在。
离线liuligang88

只看该作者 4楼 发表于: 2015-12-18
回 realfan 的帖子
realfan:感觉你是在paintEvent()调用了paintEvent(),导致无退出的深层调用,最后资源无法分配 out of memory,是内存不足 (2015-12-18 08:37) 

恩,谢谢啦@realfan  ,问题已经解决。。。
本帖提到的人: @realfan
离线liuligang88

只看该作者 5楼 发表于: 2015-12-18
回 liuligang88 的帖子
liuligang88:恩,谢谢啦@realfan    ,问题已经解决。。。 (2015-12-18 10:23) 

啊,问题还会有,而且是有时候有,有时候没有。@realfan    我该如何解决???谢谢。
本帖提到的人: @realfan
离线liuligang88

只看该作者 6楼 发表于: 2015-12-18
回 realfan 的帖子
realfan:感觉你是在paintEvent()调用了paintEvent(),导致无退出的深层调用,最后资源无法分配 out of memory,是内存不足 (2015-12-18 08:37) 

啊,问题还会有,而且是有时候有,有时候没有。
我只用了一次paintEvent(),@realfan      我该如何解决???谢谢。
本帖提到的人: @realfan
离线realfan

只看该作者 7楼 发表于: 2015-12-21
回 liuligang88 的帖子
liuligang88:啊,问题还会有,而且是有时候有,有时候没有。
我只用了一次paintEvent(),@realfan        我该如何解决???谢谢。  (2015-12-18 15:58) 

我觉得你这类问题,一般是出现了直接或间接递归调用,导致资源耗尽出错。
建议检查下有没有间接调用行为
本帖提到的人: @realfan
离线z609932088

只看该作者 8楼 发表于: 2015-12-25
我只是来抽热闹的
有阳光的地方就是青春
离线liuligang88

只看该作者 9楼 发表于: 2016-01-05
回 realfan 的帖子
realfan:我觉得你这类问题,一般是出现了直接或间接递归调用,导致资源耗尽出错。
建议检查下有没有间接调用行为 (2015-12-21 09:50) 

恩,谢谢了,已经解决。
离线realfan

只看该作者 10楼 发表于: 2016-01-05
回 liuligang88 的帖子
liuligang88:恩,谢谢了,已经解决。 (2016-01-05 14:14) 

可能的话,把查到的原因说一下吧,可以供大家参考
离线liuligang88

只看该作者 11楼 发表于: 2016-01-11
其实,是我的问题,我给几个变量malloc了一些内存,因为这是全局变量,有很多函数都会用到,所以我没有free掉,
然后我又把这些变量放在了button的槽函数中,所以多次点击就会出现内存泄露,之所以出现painter的问题,
我认为是刚好程序运行到哪里,没有内存的缘故,但其实不是painter的问题。
现在我把这些变量不放在槽函数中,放在外面只分配一次,就不会每次点击button就分配内存,也就不会内存泄露了。
快速回复
限100 字节
 
上一个 下一个