1

I try to develop little plugin for Qgis. I used custom widgets in QT that comes with QGIS 2.18 and loaded QgisMapLayerComboBox. But when I reload my plugin in QGis it gives me an error:

2018-01-14T00:06:10 1 Traceback (most recent call last): File "C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python\qgis\utils.py", line 342, in startPlugin plugins[packageName].initGui() File "C:/Users/Michal.DESKTOP-M9QN5BH/.qgis2/python/plugins\DMS2Point\DMS2Point.py", line 172, in initGui parent=self.iface.mainWindow()) File "C:/Users/Michal.DESKTOP-M9QN5BH/.qgis2/python/plugins\DMS2Point\DMS2Point.py", line 139, in add_action self.dlg = DMS2PointDialog() File "C:/Users/Michal.DESKTOP-M9QN5BH/.qgis2/python/plugins\DMS2Point\DMS2Point_dialog.py", line 30, in init self.setupUi(self) File "C:/Users/Michal.DESKTOP-M9QN5BH/.qgis2/python/plugins\DMS2Point\DMS2Point_dialog_base.py", line 48, in setupUi self.mMapLayerComboBox_2 = QgsMapLayerComboBox(self.widget) NameError: global name 'QgsMapLayerComboBox' is not defined

I don't understand the last line. Code is compiled and everything, step by step made according to tutorials 'How to make a Qgis plugin...'. This error does no appear when I use 'normal' QT ComboBoxes. I wanted to use Qgis Custom Widgets because they might be easier in use and modification.

  • 2
    Did you import QgsMapLayerComboBox from DMS2Point_dialog_base.py? – user55937 Jan 14 '18 at 15:17
  • 1
    @user55937 - Please post your comment as an answer :) – Joseph Jan 15 '18 at 10:32
  • @Joseph It wasn't intended to be answer in the comment bloc. It was a genuine question. The answer seemed pretty obvious to me, and so I just wanted to rule it out first. – user55937 Jan 15 '18 at 18:59
2

from within DMS2Point_dialog_base.py add

from qgis.gui import QgsMapLayerComboBox
1

So I found the solution for this issue. In Your main .py plugin file (YourPLugin.py) at the beginning type:

from YourPluginName_dialog_base import QgsMapLayerComboBox

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.