I've created a test plug-in in QGIS successfully, but have had a hard time implementing a signal on a vector layer event (add or modify feature). I've add this to my initGUI method:


and this definition:

def addedGeometry(self, intValue):
        QMessageBox.information( self.iface.mainWindow(),"Info", "Hi!!!" )

I get the following error when I load my plug-in:

TypeError: arguments did not match any overloaded call:
  QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
  QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
  QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): first argument of unbound method must have type 'QObject'

If anyone could help I would be very grateful! I can't find a lot of examples of implementing signals on QGIS objects.


self.iface.activeLayer() is relative to what layer is selected in the legend. If no layer is selected it returns 0 (not a QObject and resolved to 'NoneType'), which can not accept a signal/slot connection.

You'll need to do two things before building the signal/slot connection:

  1. Verify that self.iface.activeLayer() is in fact returning a QgsMapLayer and not 0
  2. Verify the active layer's LayerType is a QgsVectorLayer, which produces the featureAdded(QgsFeatureId) signal you're looking to connect to.

Edit: there is good information for writing plugins here:

Also, consider using new style PyQt connection syntax (here, once you have defined a variable 'vlayer' for the vector layer):


def addedGeometry(self, intValue):
    # fun stuff here
  • Thank you! I realized this since I posted, but have had more problems. I checked this: self.iface.mapCanvas().layerCount() and it returns 0 in my initGui method so i can't get any layer here. i think i have my signal binding in the wrong location. any advice on where to move it to? thank you, i'm very new to qGIS development and just trying it out to see if we can replace some of ESRI development w/ qGIS. – user9515 Aug 13 '12 at 19:32
  • Not sure without seeing the actual code, but it sounds like you are trying to set up your plugin's functional signal/slot connections on plugin load (i.e. during initGui()). Depending upon your plugin's function this may be the correct place for some connections. If your plugin is working with an activeLayer() you will probably want to make that connection in your plugin's class, if GUI-based, or as a conditional part of a slot connected to the self.iface.currentLayerChanged() signal. – dakcarto Aug 13 '12 at 19:52
  • thank you. this helps. i think i need to change the approach and the structure of the tool. – user9515 Aug 13 '12 at 20:04

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.