1

I have created two processing provider plugins, with the same provider name, however the second plugin is not shown in the processing toolbox and cannot be opened under plugins. I receive the following error message:

RuntimeError: wrapped C/C++ object of type has been deleted Traceback (most recent call last): File "C:/PROGRA~1/QGIS 3.16/apps/qgis/./python\qgis\utils.py", line 434, in unloadPlugin plugins[packageName].unload() QgsApplication.processingRegistry().removeProvider(self.provider) RuntimeError: wrapped C/C++ object of type has been deleted

Full script:

def __init__(self, iface):
    self.provider = None
    self.iface = iface

def initProcessing(self):
    """Init Processing provider for QGIS >= 3.8."""
    self.provider = PluginProvider()
    QgsApplication.processingRegistry().addProvider(self.provider)

def initGui(self):
    self.initProcessing()
    
    icon = os.path.join(os.path.join(cmd_folder, 'logo.png'))
    self.action = QAction(
       QIcon(icon),
       u"Algorithm 1", self.iface.mainWindow())
    self.action.triggered.connect(self.run)
    self.iface.addPluginToMenu(u"&Plugin", self.action)
    self.iface.addToolBarIcon(self.action)


    self.action = QAction(
       QIcon(icon),
       u"Algorithm 2", self.iface.mainWindow())
    self.action.triggered.connect(self.run)
    self.iface.addPluginToMenu(u"&Plugin", self.action)
    self.iface.addToolBarIcon(self.action)

def unload(self):
    QgsApplication.processingRegistry().removeProvider(self.provider)
    self.iface.removePluginMenu(u"&Plugin", self.action)
    self.iface.removeToolBarIcon(self.action)
    
def run(self):
    processing.execAlgorithmDialog("Plugin:Algorithm 1")
    processing.execAlgorithmDialog("Plugin:Algorithm 2")
    """Run method that performs all the real work"""

1
  • Yes, I would like both algorithms (algorithm 1 and algorithm 2) under the same heading (provider name).
    – GISJess
    Aug 22, 2022 at 13:41

1 Answer 1

3

Lets first understand few QGIS terminologies:

Processing Plugins Plugins that are written in QGIS processing frameworks. When a plugin is installed or QGIS is started, the plugin adds a processing provider to the registry.

Processing Provider Each Provider contains many processing algorithms. For example GDAL, GRASS, etc are processing providers.

Processing Algorithms Processing Algorithms are end tools which a user can use. For example Buffer, Clip, etc are algorithms.

If you develop two plugins with the same name. QGIS would consider them two separate plugins and when it will encounter same name things will get overwritten. You don't need to create two separate plugins. If you are looking for something like GDAL provider which has multiple algorithms. You just need to create two separate algorithms with different names and then in your Provider class import these algorithm classes and then do something like this

    def loadAlgorithms(self):
        """
        Loads all algorithms belonging to this provider.
        """
            self.addAlgorithm(algorithm1)
            self.addAlgorithm(algorithm2)


5
  • I have created two separate algorithms (algorithm1.py and algorithm2.py) and changed these in the other .py files. They now appear as I wished, however, when I open one, the other algorithm automatically opens. Do I need to change something with def unload(self)?
    – GISJess
    Aug 23, 2022 at 8:13
  • 1
    You need to name the class something different. Please provide more details when you ask question like screenshot/code sample etc Aug 23, 2022 at 9:37
  • The algorithm class names are different: class Algorithm1(QgsProcessingAlgorithm) and class Algorithm2(QgsProcessingAlgorithm). The only class name which is the same is the plugin: class name class PluginPlugin(object)
    – GISJess
    Aug 23, 2022 at 9:49
  • Make sure your load method of both algorithms are calling different algorithms respectively Aug 23, 2022 at 9:55
  • @GISJess please accept this answer if it solves the question you asked. Aug 23, 2022 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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