Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on a plugin in QGIS and want to get a signal when the geometry to a feature(in this case a polyline) in my layer is changed. For example if I use the node tool to drag one of the nodes.

In the qgis-api-documantion(http://qgis.osgeo.org/api/classQgsVectorLayer.html) i see that the line:
void geometryChanged (QgsFeatureId fid, QgsGeometry &geom) is listed under signals.

So I used this command: QObject.connect(self.iface.activeLayer(),SIGNAL("geometryChanged(QgsFeatureId, QgsGeometry)"),self.changedGeometry)

I have a method called changedGeometry:

def changedGeometry(self, intValue, qgsGeom):
    QMessageBox.information(self.iface.mainWindow(),"Message", "Changed geometry. intValue: " + str(intValue) + "qgsGeom: " + str(qgsGeom))

When executed I get this error:

TypeError: C++ type 'QgsFeatureId' is not supported as a slot argument type

I have also tried QObject.connect(self.iface.activeLayer(),SIGNAL("geometryChanged(int, QgsGeometry)"),self.changedGeometry).

Then the program do not crash, but I don't get the message about changed geometry

I am using QGIS version 1.8.0-Lisboa. Compiled against Qt 4.7.1 and these

import statements are in the top:                                                             
from PyQt4.QtCore import *    
from PyQt4.QtGui import *   
from qgis.core import *   
from qgis.gui import *

Edit: I tried using qint64 instead QgsFeatureId, but it still don't work.

QObject.connect(self.iface.activeLayer(),SIGNAL("geometryChanged(qint64,QgsGeometry)"),self.changedGeometry)

Edit2: I also tried using the new style of connecting signals and slots. self.iface.activeLayer().geometryChanged.connect(self.changedGeometry) But it gave me this error message:

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

share|improve this question
    
Could you actually report how you got it to work please ? I'm having a similar problem with featureDeleted, and need to stay with stable build 1.8 for now. Thanks. –  user2433507 Aug 6 '13 at 15:32

1 Answer 1

Ok. That was a bug in the SIP bindings. Fixed in commit:32978fb4. Apparently the names of the signals have to match in python and C++ - so qint64 doesn't work as expected.

In Windows there are still some issues, though. See bug #6573

share|improve this answer
    
I tried using qint64, but it still don't work. –  user8790 Jul 16 '12 at 10:38
    
Thank you. I got it to work with the old style. But with the new style, I still get a error message. I might have done something wrong. It is not important to me since the old style works, but I thought you might want to know. self.iface.activeLayer().geometryChanged.connect(self.geomChanged) gave this error: TypeError: connect() failed between geometryChanged(QgsFeatureId,QgsGeometry) and unislot() –  user8790 Jul 17 '12 at 8:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.