i am making a qgis plugin and want to highlight a feature from feature id but the feature id must be taken from the textbox my code is below but this shows error like
it = cLayer.getFeatures(QgsFeatureRequest(expr))
AttributeError: 'NoneType' object has no attribute 'getFeatures'
inputid = self.dlg.lineEdit.text() cLayer = self.iface.mapCanvas().currentLayer() expr = QgsExpression( "\"ID\"= 54") it = cLayer.getFeatures(QgsFeatureRequest(expr)) ids = [i.id() for i in it] if i['ID'] == inputid: cLayer.setSelectedFeatures(i['ID'])
Thanks in advance
It seems that QGIS doesn't recognize the layer.
cLayer = self.iface.mapCanvas().currentLayer()
QgsVectorLayer() object only if it is currently selected in the Layers Panel. Otherwise, a
None is returned and the error you encountered.
I don't know the source of the input layer, but a general method for loading it would be:
cLayer = QgsVectorLayer('path to the vector layer', 'display name', 'ogr')