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?

closed as off-topic by underdark May 23 '18 at 17:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – underdark
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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.

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