1

I have created a QgsRasterLayer object using:

lyr=QgsRasterLayer(url,'lyr_name')

and the layer is displayed by:

QgsProject.instance().addMapLayer(lyr)

Now when this layer is removed through:

QgsProject.instance().removeMapLayer(lyr)

I am unable to reload it on the interface. I get below error:

RuntimeError: wrapped C/C++ object of type QgsRasterLayer has been deleted

From what I understand the refrenced object of lyr is deleted. I need a workaround for this so that I can load and unload lyr multiple times. Since the layer object is created dynamically for so recreating it is not an option.

  • your first line of code says QgsVectorLayer(...) - did you mean QgsRasterLayer(...)? – Spacedman Mar 18 at 8:30
  • Yes I did.. I've edited the question – Faiz Kidwai Mar 18 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.