I am developing a plugin for QGIS in Python, I need to connect the sselectionChanged signal emitted when a feature of the layer is selected, I could not find any examples on internet, here is what I have done so far:
QObject.connect(self.iface.mapCanvas(),SIGNAL("selectionChanged(QgsMapLayer)"), self.test)
In the logs of QGIS I get this warning:
Warning: Object::connect: (receiver name: 'MainWindow')
can you help me?
Best Answer
arpho, this new style PyQt connection works for me in PyQGIS Console (Mac OS X 10.7.3, with QGIS 1.7.4)...
I had to hit return at an empty prompt to see the printed "selection changed" messages. If I changed the selection multiple times, those would show up upon hitting return.
The only thing I can see that might cause that error is if your 'self' object hasn't had the iface reference assigned. Is this in your __init__() method of your plugin's class?:
Or, that iface hasn't been passed to your plugin's class. Check your __ini__.py file for your plugin to make sure it's being passed as an argument to your plugin's class in the def classFactory() method.
Example: