Bug report #6573

QgsVectorLayer.geomChanged not connectable on Windows

Added by Rafael Varela over 11 years ago. Updated almost 8 years ago.

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

Description

A connect() that works OK on 1.9-master for Linux fails in Windows with this message:

vLayer.geometryChanged.connect(self.onNodeGeometryChange)
TypeError: connect() failed between geometryChanged(QgsFeatureId,QgsGeometry) and unislot()

The code looks like this:

    ...
    vLayer.geometryChanged.connect(self.onNodeGeometryChange)
    ...

  @pyqtSlot(int, QgsGeometry)
  def onNodeGeometryChange(self, featureId, geom ):
  ...

I had a similar problem in Linux with QGIS 1.8 wich was solved upgrading to master after being aware of 32978fb4

History

#1 Updated by Robin V. over 10 years ago

The problem still exists in QGis 2.0.1-3 available through OSGeo4W distribution. New style connection always return the same error:

TypeError: connect() failed between geometryChanged(QgsFeatureId,QgsGeometry) and unislot()

A possible workaround is to use old signal/slot code:

QObject.connect(my_vectlayer,SIGNAL("geometryChanged(QgsFeatureId, QgsGeometry&)"),mynicehandler)

instead of expected:

my_vectlayer.geometryChanged.connect(mynicehandler)

Full testcase:

from PyQt4.QtCore import QVariant, pyqtSlot, QObject, SIGNAL 
from PyQt4.QtGui import QMessageBox
from qgis.core import QgsFeature

vl = QgsVectorLayer("Point", "temporary_points", "memory") 
pr = vl.dataProvider() 
pr.addAttributes( [ QgsField("name", QVariant.String), QgsField("age",  QVariant.Int),QgsField("size", QVariant.Double) ] ) 
fet = QgsFeature() 
fet.setGeometry( QgsGeometry.fromPoint(QgsPoint(10,10)) ) 
fet.setAttributes(["Johny", 2, 0.3])
pr.addFeatures([fet])
QgsMapLayerRegistry.instance().addMapLayer(vl)
vl.updateExtents()

def mynicehandler(feat, geo):
    print "mynicehandler" 
    QMessageBox.information(iface.mainWindow(), "mynicehandler", "Here I am")

# working
QObject.connect(vl,SIGNAL("geometryChanged(QgsFeatureId, QgsGeometry&)"),mynicehandler)

# not working
vl.geometryChanged.connect(mynicehandler)

Toying with pyqtSlot annotation didn't help in any manner:

@pyqtSlot()
@pyqtSlot(qint64, QgsGeometry)
@pyqtSlot(int, QgsGeometry)

QgsFeatureId = int
@pyqtSlot(QgsFeatureId, QgsGeometry)
@pyqtSlot('QgsFeatureId,QgsGeometry&')
@pyqtSlot('QgsFeatureId,const QgsGeometry&')
@pyqtSlot('QgsFeatureId,QgsGeometry')

#2 Updated by Matthias Kuhn over 10 years ago

This very minimalistic example makes no trouble here (Linux). Manually changing geometries prints the message to the python console.

def geom_changed(fid,geom):
    print('Geometry of feature {} changed'.format(fid))

iface.activeLayer().geometryChanged.connect(geom_changed)

#3 Updated by Robin V. over 10 years ago

Even your minimalistic example fails on windows (latest qgis 2.0.1-3 shipped with OSGeo4W):

Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on HOMESTATION
## Type help(iface) for more info and list of methods.
def geom_changed(fid,geom):
    print('Geometry of feature {} changed'.format(fid))
iface.activeLayer().geometryChanged.connect(geom_changed)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: connect() failed between geometryChanged(QgsFeatureId,QgsGeometry) and unislot()

I don't know if the about box content is useful, but here it is:

QGIS version    2.0.1-Dufour    
QGIS code revision    ebebdf3
Compiled against Qt    4.7.1    
Running against Qt    4.7.1
Compiled against GDAL/OGR    1.10.1    
Running against GDAL/OGR    1.10.1
Compiled against GEOS    3.3.8-CAPI-1.7.8    
Running against GEOS    3.4.2-CAPI-1.8.2 r3921
PostgreSQL Client Version    8.3.10    
SpatiaLite Version    4.1.1
QWT Version    5.2.1    
PROJ.4 Version    480
QScintilla2 Version    2.6.2

I've seen bugs and reports around qgsvectorlayer.sip, but those seems to be solved for a year or so. The fact that "old school signal" syntax works let me think that there's a weird problem in PyQt4 and SIP black magic, but I'm not skillful enough to diagnose it better.

#4 Updated by Jürgen Fischer almost 10 years ago

  • Subject changed from Python bindings fail on 1.9-master for Windows to QgsVectorLayer.geomChanged not connectable on Windows
  • Category set to Python plugins

#5 Updated by Jürgen Fischer almost 8 years ago

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

apparently meanwhile fixed.

Also available in: Atom PDF