QGraphicsItem删除item崩溃

用QGraphicsScene删除item有时候会出现崩溃现象。

P_Scene->removeItem(item);

解决方式

使用QGraphicsScene的setItemIndexMethod(QGraphicsScene::NoIndex);
禁用索引的快速查询,即可解决上述问题。

其他

对于使用removeItem()后是否还需要delete的问题,官方问题有给出明确解释

Removes the item item and all its children from the scene. The ownership of item is passed 
on to the caller (i.e., QGraphicsScene will no longer delete item when destroyed).
从场景中remove该item及其所有子item。 item的所有权将传递给调用者(即,QGraphicsScene在销毁时将不会删除item)。

猜你喜欢

转载自blog.csdn.net/qq_40732350/article/details/121712812