[QGIS-Developer] Can we check for "wrapped C/C++ object of type QgsLayerTreeGroup has been deleted"

Richard Duivenvoorde rdmailings at duif.net
Mon Aug 31 02:27:15 PDT 2020


Hi Devs,

In a python plugin I had an issue in which somebody had created a 'group 
layer' (in a Python plugin), and saved it in 'the default project'.
BUT when the plugin did 'find' that group layer (via it's name) and 
tries do call a method on it you get the dreaded:

"wrapped C/C++ object of type QgsLayerTreeGroup has been deleted" 
message.

So my question: is there a proper way in Python, to check if the 
'underlaying' c++ object is still alive/available?
( other then in a try/except clause try to call a method :-) )
I'm gooing for the try/except hack now, but maybe it is an idea to add 
an 'isValid' or so to all PyObjects?

OR is this specific case a QGIS issue, as creating a GroupLayer maybe 
should also create a c++ grouplayer?

Regards,

Richard Duivenvoorde

PS this is NOT garbage collecting related, it is not that I can save an 
'handle' to the object: it is an (empty) grouplayer saved in a project.


More information about the QGIS-Developer mailing list