[Interest] QGraphicsScene & removing item
Igor Mironchik
igor.mironchik at gmail.com
Sat Jun 25 21:04:17 CEST 2016
Hi.
Removing of scene()->removeItem( item ); solved the problem.
I read old mailing list about such problem, yet in Qt 4. And guys
advised to put prepareGeometryChange(). I checked it, and with this
method app crashes more frequently.
And removing removeItem() solves the problem.
So problem is very old. May be somebody know what is the reason?
On 25.06.2016 19:40, Igor Mironchik wrote:
> Hi,
>
> I ran into a problem. When I delete item (QGraphicsItem) from scene I
> received following crash:
>
> 1 QGraphicsSceneFindItemBspTreeVisitor::visit
> qgraphicsscene_bsp.cpp 77 0x7ffff76aeb24
> 2 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 245 0x7ffff76ae6dc
> 3 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 259 0x7ffff76ae7ba
> 4 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 250 0x7ffff76ae71b
> 5 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 259 0x7ffff76ae7ba
> 6 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 250 0x7ffff76ae71b
> 7 QGraphicsSceneBspTree::climbTree qgraphicsscene_bsp.cpp
> 259 0x7ffff76ae7ba
> 8 QGraphicsSceneBspTree::items qgraphicsscene_bsp.cpp 152
> 0x7ffff76adb8a
> 9 QGraphicsSceneBspTreeIndexPrivate::estimateItems
> qgraphicsscenebsptreeindex.cpp 389 0x7ffff76b1c14
> 10 QGraphicsSceneBspTreeIndex::estimateTopLevelItems
> qgraphicsscenebsptreeindex.cpp 543 0x7ffff76b24d5
> 11 QGraphicsScenePrivate::drawItems qgraphicsscene.cpp
> 4712 0x7ffff76937b9
> 12 QGraphicsView::paintEvent qgraphicsview.cpp 3550
> 0x7ffff76cc13a
> 13 QWidget::event qwidget.cpp 8930 0x7ffff72b0d9e
> 14 QFrame::event qframe.cpp 550 0x7ffff73ff4a5
> 15 QAbstractScrollArea::viewportEvent qabstractscrollarea.cpp
> 1213 0x7ffff74b92e0
> 16 QGraphicsView::viewportEvent qgraphicsview.cpp 2973 0x7ffff76c9930
> 17 QAbstractScrollAreaPrivate::viewportEvent
> qabstractscrollarea_p.h 111 0x7ffff74ba6d3
> 18 QAbstractScrollAreaFilter::eventFilter
> qabstractscrollarea_p.h 127 0x7ffff74ba7be
> 19 QCoreApplicationPrivate::sendThroughObjectEventFilters
> qcoreapplication.cpp 1099 0x7ffff65a222f
> 20 QApplicationPrivate::notify_helper qapplication.cpp
> 3795 0x7ffff725a201
> ... <More>
>
> Where visit() is:
>
> void visit(QList<QGraphicsItem *> *items) Q_DECL_OVERRIDE
> {
> for (int i = 0; i < items->size(); ++i) {
> QGraphicsItem *item = items->at(i);
> if (onlyTopLevelItems && item->d_ptr->parent)
> item = item->topLevelItem();
> if (!item->d_func()->itemDiscovered &&
> item->d_ptr->visible) {
> item->d_func()->itemDiscovered = 1;
> foundItems->prepend(item);
> }
> }
> }
>
> I did two deletions and in this method I received two broken
> QGraphicsItems:
>
>
> Locals
> i 1 int
> item @0x706990 QGraphicsItem
> [vptr] <not accessible>
> [0]
> d_ptr 12884901888 QScopedPointer<QGraphicsItemPrivate,
> QScopedPointerDeleter<QGraphicsItemPrivate> >
> items <4 items> QList<QGraphicsItem*>
> [0] @0x866070 Prototyper::Core::GridSnap
> [1] @0x706990 QGraphicsItem
> [vptr] 0x0
> d_ptr 12884901888
> QScopedPointer<QGraphicsItemPrivate,
> QScopedPointerDeleter<QGraphicsItemPrivate> >
> [2] @0x706990 QGraphicsItem
> [vptr] 0x0
> d_ptr 12884901888
> QScopedPointer<QGraphicsItemPrivate,
> QScopedPointerDeleter<QGraphicsItemPrivate> >
> [3] @0x866110 Prototyper::Core::Form
> this @0x865f40 QGraphicsSceneFindItemBspTreeVisitor
> Inspector
> Expressions
> Return Value
> Tooltip
> FormAction <not accessible>
> FormResizeHandle <not accessible>
> Q_DECL_OVERRIDE <no such value>
> WithResizeAndMoveHandles <not accessible>
> foundItems <1 items> QList<QGraphicsItem*>
> m_bottom <not accessible>
> onlyTopLevelItems true bool
> setDeltaToZero <not accessible>
>
> My delete method is:
>
> void
> Form::deleteItems( const QList< QGraphicsItem* > & items )
> {
> foreach( QGraphicsItem * item, items )
> {
> if( item == d->m_current )
> d->m_current = 0;
>
> FormObject * obj = dynamic_cast< FormObject* > ( item );
>
> if( obj )
> {
> pushUndoDeleteCommand( d->m_undoStack, obj, this );
>
> d->m_model->removeObject( obj, this );
>
> d->removeDescriptions( obj );
> }
>
> scene()->removeItem( item );
>
> if( obj )
> {
> d->m_model->endRemoveObject();
>
> d->m_ids.removeOne( obj->objectId() );
>
> switch( obj->objectType() )
> {
> case FormObject::GroupType :
> {
> FormGroup * group = dynamic_cast< FormGroup* > (
> item );
>
> if( group )
> {
> d->clearIds( group );
>
> group->postDeletion();
> }
> }
> break;
>
> default :
> {
> obj->postDeletion();
> }
> break;
> }
> }
>
> delete item;
> }
> }
>
> I do scene()->removeItem( item ); and delete item; but in the
> internals of QGraphicsScene I got two damaged pointers...
>
> What is the problem? Thank you.
>
> P.S. postDeletion() methods now is empty, like:
>
> void postDeletion()
> {
> }
>
More information about the Interest
mailing list