[QGIS-Developer] Problems accessing Dockwidget Features

Luís Miguel Royo Pérez luis.miguel.royo at gmail.com
Fri Dec 29 03:58:00 PST 2017


Hello, 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 "/home/luismi/.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.


-- 
Luís Miguel Royo Pérez.
Analista-Programador GIS
Av. Blasco Ibañez nº 1. Manises (Valencia)
Teléfono: 679846103
web: inisig.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171229/31ab6229/attachment-0001.html>


More information about the QGIS-Developer mailing list