I'm trying to teach myself to make my first QGIS plugin. I used the Plugin Builder to create the base python files, and the plugin seems to work fine when I press the toolbar icon. I'm now trying to allow the user to use a keyboard shortcut to trigger the plugin as if they were pressing the "ok" button in the plugin dialog - assuming the plugin dialog is already open. I've done something wrong and now my menu item is repeated in more than one place and I can't remove them:enter image description hereenter image description here

I had trouble getting the method described here to work, and only later realized I wasn't unloading correctly, or at all.

My plugin loading in the initGui is certainly wrong, but so is my current unload wrong:

def unload(self):
    """Removes the plugin menu item and icon from QGIS GUI."""
    for action in self.actions:
            self.tr(u'&Copy Attributes'),
            self.tr(u'&Please Copy the Attributes'),
    # remove the toolbar
    del self.toolbar

I've used the Settings -> Configure Shortcuts manager to remove shortcuts, but I have multiple entries there as well. I originally tried to create a shortcut for the plugin by just using the Shortcut Manager, but it didn't work, so that's why I started trying to do it in the initGui.

I'm not sure of the correct method to unload a menu or toolbar item, but will ask this in a different question.

Update: I've managed to figure out how to remove the duplicate menu items. I simply restarted QGIS without the plugin loaded. Then reloaded it from the Plugin Manager. The duplicate menu entries have now disappeared.

closed as off-topic by Andre Silva, whyzar, BERA, aldo_tapia, xunilk Jan 3 '18 at 20:19

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

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Andre Silva, whyzar, BERA, aldo_tapia, xunilk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    Hi Jan, you can answer your own question (about properly unloading the plugin). This way it will serve as reference for other people with the same problems. Then please open a new question with the other problem (to stay in line with the philosophy of 1 question each). – Matthias Kuhn Aug 10 '16 at 6:42