I've made a bit of a plugin to handle badlayers (I'm aware that Change datasource plugin had something for this but the code appears to have been removed now?). I've followed the advice provided in How to set default bad layers handler in the python plugin? and I can get the handler to start when layers are missing.

I'm currently having trouble setting the new data provider. Currently I'm doing

handler = QgsProjectbadLayerHandler()

newPath = "C:\pathtomissinglayer"


where domNode has been passed in from handleBadLayers(self, domNodes)

This doesn't work as expected. The layers still disappear and setting the data source doesn't seem to change anything even though it executes properly. Should I be passing in the newPath as a string or something else? And how do I stop the layers from disappearing?

Edit: There appears to be a new class as a part of 3.6?? called QgsStoreBadLayerInfo. Description says it stores layer IDs of bad layers. The ID could be useful to get the position of the map layer in the layer explorer and then just create a new layer with the correct file path. As is extends from QgsProjectBadLayerHandler could this class just be used in place of QgsProjectBadLayerHandler? Will it be called when layers are missing? I tried but couldn't get it too work

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.