danics
5th August 2015, 05:37
Hi everybody, I'm using Qt 5.4 and it seems prepareGeometryChange doesn't work correctly!!
I create a RouteItem inherit from qgraphicsobject include some lines and some nodes ( Node is another qgraphicsitems with fixed boundingrect ). when I move my nodes or change scale of my scene the RouteItem's shape changed and I call the prepareGeometryChange function of qgraphicsitem.
Everything looks OK I can select my item or right click on it, but strange problem happened when I want to delete one RouteItem, program crashed on the QGraphicsSceneFindItemBsbTreeVisitor::visit ??
this is my deletion code
void RouteItem::deleteRoute()
{
prepareGeometryChange(); // add if I forgot to call it before
m_parentScene->update(); // add this line for taking effect of prepareGeometryChange and recalculate items boundry
m_parentScene->removeItem(this);
deleteLater();
}
RoteItem::~RouteItem()
{
foreach(Waypoint* nd, nodeList) {
m_parentScene->removeItem(nd);
nd->deleteLater();
}
}
QPainterPath shape() const
{
QPainterPathStrocker strocker;
// read all nodes calculate some geographical equations and create a path from items positions
return strocker.createStroke(path);
}
QRectF boundingRect() const
{
if(nodeList.count())
return shape().boundingRect();
return QRectF();
}
thanks in advance.
I create a RouteItem inherit from qgraphicsobject include some lines and some nodes ( Node is another qgraphicsitems with fixed boundingrect ). when I move my nodes or change scale of my scene the RouteItem's shape changed and I call the prepareGeometryChange function of qgraphicsitem.
Everything looks OK I can select my item or right click on it, but strange problem happened when I want to delete one RouteItem, program crashed on the QGraphicsSceneFindItemBsbTreeVisitor::visit ??
this is my deletion code
void RouteItem::deleteRoute()
{
prepareGeometryChange(); // add if I forgot to call it before
m_parentScene->update(); // add this line for taking effect of prepareGeometryChange and recalculate items boundry
m_parentScene->removeItem(this);
deleteLater();
}
RoteItem::~RouteItem()
{
foreach(Waypoint* nd, nodeList) {
m_parentScene->removeItem(nd);
nd->deleteLater();
}
}
QPainterPath shape() const
{
QPainterPathStrocker strocker;
// read all nodes calculate some geographical equations and create a path from items positions
return strocker.createStroke(path);
}
QRectF boundingRect() const
{
if(nodeList.count())
return shape().boundingRect();
return QRectF();
}
thanks in advance.