6

I have recently developed a Processing plugin for QGIS 3.16, which aims to analyze biodiversity data from a specific PostgreSQL database (https://github.com/lpoaura/PluginQGis-LPOData). It is used by several employees in our company.

For each algorithm, a spatial or non-spatial layer is created and its table of content is opened at the end of the code execution, with the following command:

iface.showAttributeTable(output_layer)
iface.setActiveLayer(output_layer)

Depending on people feedback, two problems can be faced here :

  • either the table of content opens up and closes immediately without having displayed the content;
  • or the table of content opens up and gets frozen (that means that you can’t even scroll or select an action from the window). You need to close it and open again to fix the problem.

I can’t find any error message on QGIS desktop after this, so I don’t know what’s happening. Apparently this issue has already been raised but I can’t find it...

I would like to recommend installing the plugin and trying it, but it can be used only with a specific database… Has anyone ever faced this problem? Any fix for this?

9

You should use showAttributeTable inside postProcessAlgorithm method. Also, add self. to layer* variables to be able to access them in postProcessAlgorithm method.

For example:

def processAlgorithm(self, parameters, context, feedback):
    
    # other stuffs
    
    # Add 'self'
    self.layer_map = QgsVectorLayer(...)

    # Remove two following lines. You will add those to postProcessAlgorithm method
    # iface.showAttributeTable(layer_map)
    # iface.setActiveLayer(layer_map)    

    # other stuffs


def postProcessAlgorithm(self, context, feedback):

    lyr = QgsProcessingUtils.mapLayerFromString(self.layer_map, context)

    iface.showAttributeTable(lyr)
    iface.setActiveLayer(lyr)

    return {}

enter image description here

1
  • This works perfectly :) Many thanks !!! Aug 31 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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