post

How to get rid of “unknown enum QgsMapLayerProxyModel::PluginLayer” in Qgis ?

I was developping a plugin in Qgis with the Combobox layer (QgsMapLayerComboBox) which allows you to show all opened layer in Qgis. It’s a great tool that allows the user to select a raster or a vector easily.
On Ubuntu everything works perfectly, but when I was trying on Windows I always had this error when loading the plugin “error enum : QgsMapLayer”.

After long hours of research I finally found what was bugging. The ui file that use QgsMapLayerProxyModel::PluginLayer is badly compiled in the code. The solution I found is to compile the ui and change the call of the file.

Compile your ui in py

To compile your ui in py the easiest way is to use pyuic4 :

pyuic4 YourForm.ui -o YourForm.py 

Change the call of your UI form

If you used Plugin Builder you have a file yourplugin_dialog.py that looks like something like this :

FORM_CLASS, _ = uic.loadUiType(os.path.join(
    os.path.dirname(__file__), 'YourForm.ui'))

class YourDialog(QtGui.QDialog, FORM_CLASS):
    def __init__(self, parent=None):
        super(YourDialog, self).__init__(parent)
        self.setupUi(self)

You have to change it, but first you need to import your compiled form :

from YourForm import Ui_YourForm

Ui_YourForm is the class name inside YourForm.py.

Then you have to change the call to :

class YourDialog(QDockWidget, Ui_YourForm):
    def __init__(self, parent=None):
        super(YourDialog, self).__init__(parent)
        self.setupUi(self)

Of course you have to remove the line ‘FORM_CLASS, _ …‘ which doesn’t load anything now.