Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

Check your if statement: It says widget when you probably meant m_widget. If widget is non-null and m_widget is null, your program will crash, since the calls to removeItem/delete will attempt to reference a null pointer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top