Class: QgsVectorLayerFeatureCounter

class qgis.core.QgsVectorLayerFeatureCounter

Bases: QgsTask

Counts the features in a QgsVectorLayer in task. You should most likely not use this directly and instead call QgsVectorLayer.countSymbolFeatures() and connect to the signal QgsVectorLayer.symbolFeatureCountMapChanged().

New in version 3.0.

QgsVectorLayerFeatureCounter(layer: QgsVectorLayer, context: QgsExpressionContext = QgsExpressionContext(), storeSymbolFids: bool = False) Create a new feature counter for layer.

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
featureCount(self, legendKey: str) int

Returns the feature count for a particular legendKey. If the key has not been found, -1 will be returned.


legendKey (str) –

Return type


featureIds(self, symbolkey: str) object

Returns the feature Ids for a particular legendKey. If the key has not been found an empty QSet will be returned.

New in version 3.10.


symbolkey (str) –

Return type


finished(self, result: bool)

If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination). The result argument reflects whether the task was successfully completed or not. This method is always called from the main thread, so it is safe to create widgets and perform other operations which require the main thread. However, the GUI will be blocked for the duration of this method so tasks should avoid performing any lengthy operations here.

isCanceled(self) bool

Will return True if task should terminate ASAP. If the task reports the CanCancel flag, then derived classes’ run() methods should periodically check this and terminate in a safe manner.

isSignalConnected(self, QMetaMethod) bool
receivers(self, PYQT_SIGNAL) int
run(self) bool

Calculates the feature count and Ids per symbol

Return type


sender(self) QObject
senderSignalIndex(self) int
setProgress(self, progress: float)

Sets the task’s current progress. The derived class should call this method whenever the task wants to update its progress. Calling will automatically emit the progressChanged signal.


progress – percent of progress, from 0.0 - 100.0


Emitted when the symbols have been counted. [signal]

timerEvent(self, QTimerEvent)