I am trying to implement a desktop application with PyQGIS 3. When I try to use openFeatureForm to display the data of the selected layer object it shows an error, however when I use this code in the Python Console in QGIS it works correctly.

How can I use it for the application I'm doing outside of QGIS?

def info(self):
    self.vlayer = QgsVectorLayer('provincias.shp', "Provincias", "ogr")
    layer = self.vlayer
    features = layer.getFeatures()
    feat = layer.getFeature(2)
    iface.openFeatureForm(layer, feat, True)

This is the console error :

Traceback (most recent call last):
  File "D:/proyectos/catastroesp/catastro.py", line 111, in info
    iface.openFeatureForm(layer, feat, True)
AttributeError: 'NoneType' object has no attribute 'openFeatureForm'

1 Answer 1


iface is predefined variable in QGIS. It is defined while QGIS starts and refers to QGIS interface. That means you can use iface only within QGIS.

If you would like to show a feature form as in QGIS, you need to design it for your standalone application.

  • Thank you very much, that's why it works fine on the console. I will have to design the forms Commented Dec 23, 2020 at 20:50
  • It is easy to make a simple form containing only attribute names and its values for feature. Commented Dec 23, 2020 at 20:56

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.