Like ArcGIS Editor Tracking, I am trying to design attribute field with self update date feature called Updated Date in QGIS. I am following Making automatic updated date and time field in QGIS this link to get calculate it automatically but while doing so, the QGIS project is getting crashed every time. I am selecting only one feature but still it is getting crashed. I checked the code and it is running fine in Python console but not in Plugin. Please suggest.
Python Code for reference:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fields().lookupField('fieldName')
e = QgsExpression( " $now " )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate()
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
layer.geometryChanged.connect(update)