3

I'm writing a QGIS plugin but I'm facing some basic problems. The plugin is a dockwidget. I've built it with plugin Builder and then compiled the resources file.

When I try to access the comboBox to populate it with values, an error happens:

self.dockwidget.comboBox.clear() AttributeError: 'NoneType' object has no attribute 'comboBox'

I checked in the Qt _Designer the object name and it's comboBox. When I do the same with a dialog plugin, instead a dockwidget, everything seems to be right, and the comboBox is populated. This is the code for the run method.

def run(self):
    """Run method that loads and starts the plugin"""
    self.dockwidget.comboBox.clear()
    for i in range(9):            
        self.dockwidget.comboBox.addItem(str(i))

    if not self.pluginIsActive:
        self.pluginIsActive = True

        #print "** STARTING PruebaExp"

        # dockwidget may not exist if:
        #    first run of plugin
        #    removed on close (see self.onClosePlugin method)
        if self.dockwidget == None:
            # Create the dockwidget (after translation) and keep reference
            self.dockwidget = PruebaExpDockWidget()

        # connect to provide cleanup on closing of dockwidget
        self.dockwidget.closingPlugin.connect(self.onClosePlugin)

        # show the dockwidget
        # TODO: fix to allow choice of dock location
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.show()

I don't know if it's related, but when I try to create a signal this error is show:

File "XXXXXXXXXXX/PruebaExp.py", line 176, in initGui self.dockwidget.signalBox.connect(self.enviadato) AttributeError: 'NoneType' object has no attribute 'signalBox'

Same error when I try to acces a pushButton:

File "/xxxx/xxxx/.qgis2/python/plugins/PruebaExp/PruebaExp.py", line 221, in run self.dockwidget.pushButton.clicked.connect(self.enviadato) AttributeError: 'NoneType' object has no attribute 'pushButton'

Maybe is due to something I missed during the building of the plugin. I'm using QGIS 2.18.14.

1 Answer 1

3

I reply myself here, according with the solution given in the qgis developers mail list.

In the initGui function I should add this line:

self.dockwidget = GeoFibraDockWidget()

Is the constructor for the dockwidget.

1
  • Don't forget to accept your answer by clicking the green-faded tick on the left-hand side :)
    – Joseph
    Commented Jan 5, 2018 at 11:43

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.