ie.geologyidea.com
More

PyQGIS: feature added signal throws an error message

PyQGIS: feature added signal throws an error message


We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.


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 thefeatureAddedsignal properly?


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

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

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

This should solve your problem!


Watch the video: QGIS Python PyQGIS - Show Error, Warning, and Success Messages