I have created some QGIS plugin using PyQGIS those plugins have different input layer methods, some work to get layer by name from layer panel some plugin have compo_box to define the user where layer want from layer panel of QGIS.

Those plugins have a some error, if the input layer is wrong or missing from layer panel then it crashes, but if I replace with correct layer without closing QGIS then again don't work with the some way keep the wrong layer again.

If I use reload plugin and run the script with correct layer then plugin work correct.

But how to avoid to run all time reload plugin?

Can I have in my plugin some code to do re-reload every time the plugin running?

  • 2
    I don't think plugins should have to be reloaded (unless they are being tested in a development process). Instead you should include some logic into the code which checks if the layer exists and if not, show some sort of error message. Your question is somewhat similar to this one: PyQGIS get layers by name errors where a try: except method could work. Could you perhaps edit your question to include some of the code you are using and where the error comes from? :) – Joseph Jun 9 '17 at 13:42
  • @Joseph error say out of range correct but I try to use try:except and I have some error – jessie jes Jun 12 '17 at 20:26

Not really plugin code, but you can re-install the plugin through the plugin manager to avoid restarting Qgis.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.