I am using QGIS 2.8. For the documentation of QgsExpression I see the evaluate method on feature as deprecated. What am i supposed to use instead of this methods ? I have some expression and need to check if expression evaluate to True or False on given feature.

enter image description here

  • I don't know if that could be applied to your case, but a QgsExpression can be used in a QgsFeatureRequest in order to call the .getFeatures() method of the layer. Like this : request = QgsFeatureRequest(QgsExpression("time < 60 AND id_origine = 12")) for feature in your_layer.getFeatures(request): #Do something on the feature... (i can elaborate in an answer if needed)
    – mgc
    Nov 13, 2015 at 19:27
  • No i don't to do this. I had to perform validation check on new feature. So when i create will create a new Feature i want to apply expression and see if it contains some inconsistent data. Nov 13, 2015 at 20:32

1 Answer 1


You're looking at the docs for >= 2.12, not 2.8. That's the correct method to use for the QGIS 2.0 series, but in QGIS 3.0 you'll need to use the method which takes a QgsExpressionContext argument. That's only available in QGIS 2.12 and up.

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.