Qt 图形视图框架 QGraphicsSceneBspTree出现的崩溃问题

Qt 图形视图框架 QGraphicsSceneBspTree出现的崩溃问题
现象
最近在处理了Qt视图中的崩溃问题,删除动态图元宕机报pure virtual method called,debug定位问题出在了QGraphicsSceneFindItemBspTreeVisitor::visit()函数中

原因
问题在于item的boundingRect()是动态获取动态改变的图元,图元修改的BoundingBox时没有预先通知Scene,使得其通过Bsp树查找图元信息时出错导致的。

解决
动态改变图元大小时,加入prepareGeometryChange()告知

结论

If you want to change the item’s bounding rectangle, you must first
call prepareGeometryChange(). This notifies the scene of the imminent
change, so that it can update its item geometry index; otherwise, the
scene will be unaware of the item’s new geometry, and the results are
undefined (typically, rendering artifacts are left within the view).

由于在自定义图元移动或者boundingrect变化时,没有提前调用prepareGeometryChange(),导致场景内可能存在无效的item索引,在绘图过程中引发崩溃。

参考:
https://blog.csdn.net/xuebin5260/article/details/50477931
https://blog.csdn.net/smilexx21/article/details/88789315

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值