[GIS] How to get the feature id after featureAdded signal (PyQGIS)

pyqgisqgis

I'm trying to make an edit form in QGIS (Python code) ,and i want after feature drawing to get the id, and the feature to be selected.
Do you have any ideas to do that?

Tried so far:

self.iface.activeLayer().featureAdded.connect(self.myfonction)

def myfonction(self): 
    for feat in self.iface.activeLayer().getFeatures():
        self.iface.activeLayer().setSelectedFeatures([feat.id()]) 

Best Answer

From the doc, it seems that featureAdded sends the feature id as argument. You can replace def myfonction(self) with def myfonction(self, fId) and use fId in your function.