QGraphicsView crash
-
I have a control that inherits from QGraphicsView. After the control loads an image, exit the program will have an exception: 0x00007FFA3E98C501 (d2d1.dll) : 0xC0000005:
the code is simple:
m_Scene.setBackgroundBrush(QBrush(Qt::blue));
m_Scene.addItem(&m_ImageItem);
setScene(&m_Scene); -
I have a control that inherits from QGraphicsView. After the control loads an image, exit the program will have an exception: 0x00007FFA3E98C501 (d2d1.dll) : 0xC0000005:
the code is simple:
m_Scene.setBackgroundBrush(QBrush(Qt::blue));
m_Scene.addItem(&m_ImageItem);
setScene(&m_Scene);@WENGSHIYING
You should run it under debugger, allow it to crash, and look at the stack trace pane.m_Scene.addItem(&m_ImageItem);Check the scope/lifetime of
m_ImageItem. It is unusual to add an item from the stack, try allocating it on the heap? And also check what is inm_ImageItem, is it valid? -
@WENGSHIYING
You should run it under debugger, allow it to crash, and look at the stack trace pane.m_Scene.addItem(&m_ImageItem);Check the scope/lifetime of
m_ImageItem. It is unusual to add an item from the stack, try allocating it on the heap? And also check what is inm_ImageItem, is it valid?@JonB
Jon has a good point. Check here out
https://doc.qt.io/qt-5.15/qgraphicsscene.html#addItem
void QGraphicsScene::addItem(QGraphicsItem *item)
Adds or moves the item and all its children to this scene. This scene takes ownership of the item.m_ImageItem has to be a pointer created on Heap.