1

For my PyQGIS plugin 2.2, I try to:


def logFeatureAdded(self,layerId,addfeatures): 
    message = str(layerId) + " has features added: " 
    for feature in addedFeatures: 
        message += str( feature.id() ) + ", " 
    QgsMessageLog.logMessage(message) 
    QApplication.beep() 

    layer.featureAdded.connect(self.logFeatureAdded)

When I try to add a feature, this following error message appears:

TypeError : logFeaturesAdded() takes exactly 3 arguments (2 given).

How can I use the featureAdded signal properly?

1

As you can see in the QGIS API docs, the featureAdded signal only passes one argument, namely, the feature ID.

When you create your slot, you must use a single argument (besides self), this way:

def logFeatureAdded(self, fid): 
    message = str( fid )
    QgsMessageLog.logMessage(message) 
    QApplication.beep() 

This should solve your problem!

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.