I'm working on a plugin for QGIS 3 and I'm fighting with the
I don't know how how to evaluate the expression added in the box and get the corresponding features as a python list.
Within the plugin I would like to write a function to call that is able to know if in the
QgsFieldExpressionWidget is a simple field (without expression) or a expression that has to be evaluated.
No problem for the first part, but API changed for the
QgsFieldExpression and I'm not able to follow the instruction of the pyqgis cookbook.
This is the function I'm trying to write:
def getFields(lay, exp): # vector layer from the combobox vl = lay.currentLayer() # vector field (or expression) field = exp.currentText() data =  # get the data from the layer # no expression if not exp.currentField(): for i in vl.getFeatures(): data.append(i[field]) # if expression is selected # this is the piece of code that is not working for QGIS 3 else: # expression name fil = exp.currentField() # expr = QgsExpression(fil) # for i in vl.getFeatures(): # data.append(expr.evaluate(i, vl.pendingFields())) return data