Bug report #6675

QgsVectorLayer.featureCount() returns always zero with Python

Added by zicke - over 11 years ago. Updated about 11 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:-
Affected QGIS version:master Regression?:No
Operating System:Ubuntu Easy fix?:No
Pull Request or Patch supplied:No Resolution:worksforme
Crashes QGIS or corrupts data:No Copied to github as #:15847

Description

The QgsVectorLayer.featureCount() method returns zero with python.

  1. Load a Postgis layer
  2. Select layer in legend
  3. Execute Python script in console:
from qgis.utils import iface
from PyQt4.QtCore import *
from PyQt4.QtGui import *
mc = iface.mapCanvas()
vlayer = mc.currentLayer()
vlayer.featureCount()

It returns the correct count of feature with python when show the features in the legend.

Works with QGIS 1.8.

History

#1 Updated by Giovanni Manghi over 11 years ago

  • Status changed from Open to Feedback

if it is a regression in master please tag this as blocker.

#2 Updated by zicke - over 11 years ago

  • Priority changed from Normal to Severe/Regression

#3 Updated by Martin Dobias over 11 years ago

Works for me - tried with a simple point layer. Isn't that specific to a particular layer / server? Is that a view? Are you using a query? Will it always return zero even after some operations on layer, e.g. show attribute table?

#4 Updated by Jürgen Fischer about 11 years ago

  • Resolution set to worksforme
  • Status changed from Feedback to Closed

Works for me too. Closing for the lack of feedback.

Also available in: Atom PDF