[Qgis-user] QGIS 2.18.9 crash using Python console

Richard Duivenvoorde rdmailings at duif.net
Tue Jun 6 22:59:55 PDT 2017


On 06-06-17 22:18, johnrobot wrote:
> Hi
> I had a look at the python examples at
> http://www.qgistutorials.com/en/docs/getting_started_with_pyqgis.html. I
> noticed that when I run
> 
> layer = iface.activeLayer()
> for f in layer.getFeatures():
>   print geom.asPoint()
> 
> QGIS crashes and creates a dump file. Is this a known issue? Running
> 
> layer = iface.activeLayer()
> for f in layer.getFeatures():
>   geom = f.geometry()
>   print geom.asPoint()
> 
> works fine. I use Windows 10, 64 bit and QGIS 2.18.9, 64 bit.

In your first loop, geom appears to be None in the loop, unless you set
it somewhere else and the loop and that geom is totally not related...

On Linux you get a decent (non crashing) error:

Python Console
Use iface to access QGIS API interface or Type help(iface) for more info
layer = iface.activeLayer()
for f in layer.getFeatures():
  print geom.asPoint()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'getFeatures'

Windows/QGIS should not crash on that anyway, can other Windows users
confirm the crash? If so, I think this is worth a ticket.

Regards,

Richard




More information about the Qgis-user mailing list