I would also use `foreach(QgsFeature* feature, features)` here.  Saves having to dereference the pointer everywhere.