1

I have created a new plugin in QGIS3 with PyQt5 using Plugins Builder and when i want to add my code in module.py gives an error

the code used is

    layers = self.iface.legendInterface().layers()
    layer_list = []
    for layer in layers:
            layer_list.append(layer.name())

    self.dlg.comboBox.addItems(layer_list)

the error message is

AttributeError: 'QgisInterface' object has no attribute 'legendInterface' Traceback (most recent call last): File "C:/Users/REDADRISSI/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\reda\module.py", line 187, in run layers = self.iface.legendInterface().layers() AttributeError: 'QgisInterface' object has no attribute 'legendInterface'

marked as duplicate by Community Apr 18 '18 at 16:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Hello Kadir, thanks for your reaction, i tried this solution and gives another error NameError: name 'QgsProject' is not defined – REDA DRISSI Apr 18 '18 at 15:45
  • Adding from qgis.core import QgsProject will probably fix your problem. – Kadir Şahbaz Apr 18 '18 at 15:48

Browse other questions tagged or ask your own question.