PDA

View Full Version : Clearing a QTreeWidget in CustomContextMenuRequest causes crash



Perrykipkerrie
4th July 2017, 16:52
Hi,

I'm struggling to get the following work:
Ive connected a CustomContextMenuRequest to a QWidgetTree and indeed the menu pops open. But, however, when I want to clear this QWidgetTree in this request I get a null pointer exception. When i run this piece of code in another place or slot it works just fine.

When there are multiple items present in the treewidget, i can delete them one for one, and everything works fine, but when I delete the last one the exception occurs again.



void N3LAB_Software::contextMenuTree(const QPoint& pos){
this->objectList->clear(); % The QTreeWidget
}


Does somebody know whats causing this problem or how to fix this?

Thanks,

Perry

Ps:
Im using Qt 5.6 with visual studio 2015

gvanvoor
5th July 2017, 13:40
The cause is probably that the context menu is still visible when the underlying model is cleared. You could try to delay the clearing of the widget by using a custom event (QApplication::postEvent and then clear the widget when the event is processed).

Perrykipkerrie
6th July 2017, 17:24
Already solved the problem,

The cause was that there was a selectionchanged signal while there were no objects left.

Thanks