从Qt5Widgets调用setFixedSize()时出现未处理的异常
Unhandled exception while calling setFixedSize() from Qt5Widgets
我正在visual studio中使用Qt库开发一个代码。作为Qt班的孩子,我有一个a级班。
class A::A(QWidget *parent, QGLWidget *shareWidget)
: QGLWidget(parent, shareWidget)
这个类的成员函数之一是:
void A::setImage(Image *image)
{
m_image = image;
setFixedSize(image->width(), image->height());
}
(其中setFixedSize是父类QWidget的一个方法)
在以下事件中从另一个类调用该方法:
bool B::event(QEvent* e)
{
QWidget::event(e);
...
A instA = new A();
instA.setImage(*image)
...
}
以下异常在setFixedSize处抛出,尽管传递的值实际上是普通的int,比如width=height=500。
Unhandled exception at 0x54A6B056 (Qt5Widgetsd.dll):
0xC0000005: Access violation reading location 0x939394BC.
这个方法setImage在运行代码时调用了好几次,效果非常好。这个问题只出现在B::event(QEvent*e)中。
PS:这个方法在这一点上不起作用,即使我直接传递像setFixedSize(500500)这样的常数值。
期待任何建议。
A instA = new A();
instA.setImage(*image)
这在我看来很荒谬。你能给出准确的编译代码吗。
其次,在使用pointers
时,请确保它们不是null
所以你的功能应该是这样的-
void A::setImage(Image *image)
{
if(image) //Null check, it will enter to block only if image is not null
{
m_image = image;
setFixedSize(image->width(), image->height());
}
}
相关文章:
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- C++ 程序中双链表的未处理异常
- 运算符重载时未处理<<异常
- 实验室中0x6BE20E11 (ucrtbased.dll) 的未处理异常.exe: 0xC0000005:访问冲突读取
- ImageMagick 的未处理异常
- 类数组大小为的未处理异常
- 尝试将构造函数设置为 0 - c++ 的未处理异常
- Dijkstra 中0x001e1078 s_Algorithm.exe的未处理异常:0xC0000005:访问冲突读取位置0xbaadf00d
- 运算符重载未处理异常
- 尝试使用 fread 读取文本文件时发生 'System.AccessViolationException' 类型的未处理异常
- c++中的Guard,在main中未处理异常时不调用析构函数
- 某些内存位置的未处理异常
- 错误 linkedlist .exe 中0x00D0345E处的未处理异常: 0xC0000005:访问违规写入位置0x
- 仅在发布模式下使用 glGenBuffer 的未处理异常 - QT
- 如何分析VS2010在调试模式下捕获的未处理异常
- glDrawArrays上的openGL未处理异常(GL_TRIANGLES,0,model.indicesCount)
- 使用Boost Spirit解析语法的未处理异常
- 解析"%Z" C++ 中将错误作为访问 voilation 的未处理异常给出?
- 为什么在win32计时器回调中引发的未处理异常未被调试器视为未处理异常