PDA

View Full Version : crash after QGraphicsProxyWidget is removed from a scene



paksas
9th February 2014, 20:35
Hi

I have a simple scene with a QGraphicsProxyWidget added to it ( and some widget set on it ). If I try removing it from the scene, like so:


if ( widget )
{
parentScene->removeItem( m_widget ); // m_widget is a QGraphicsProxyWidget
delete m_widget; // I also tried m_widget->deleteLater() here - same result
m_widget = NULL;
}


I get an instant crash - no descriptive callstack though that would tell me what's wrong ( some windows related calls in the callstack, and that's all ).

I'm using version 5.1.1 of the Qt library, I've searched the manual and the net for an instruction how to actually remove such a widget, and it's not documented at all, so I'm not sure if I'm doing something wrong there, or is there a bug in the library.

I'd appreciate any help.
Cheers,
Piotr

anda_skoa
9th February 2014, 20:57
Maybe the widget get deleted, triggers a delete of the proxy and you delete is then a double delete.

Have you tried just deleting the item, i.e. without removing it from the scene?

Cheers,
_

paksas
9th February 2014, 22:28
It gets deleted, but as a result of the proxy being deleted, so that's not it :(

Added after 4 minutes:

There are 2 additional circumstances:

- the crash doesn't occur until I make a scene query ( i.e. QGraphicsScene::items( QpointF() ... )
- I'm calling hide/show on the embedded widget. If I stop doing that, the crashing stops.

Added after 46 minutes:

I found the problem - seemingly unrelated call to 'prepareGeometryChange' was to blame here.
My widgets were changing size ( I didn't mention it, 'cause it seemed irrelevant at the time ). However I was calling the aforementioned method AFTER I made the change to the geometry, not before, as the manual instructs.

Apparently that method is very important in order to keep the scene's internal data in order, and due to my calling it incorrectly, it was leaving some invalid references to the deleted items.