[Qgis-user] Check if a selectionChanged signal is connected to any slot?

Tudorache, Marian Marian.Tudorache at navcanada.ca
Tue Oct 3 04:48:13 PDT 2017


Hi Mathias,

Yeah, this is what I knew in theory. Unfortunately this is not the case.
You can try in python console.
Make sure you have a layer with some features.
Define function executeAfterSelection where you do some dummy printing.
Call three times layer.selectionChanged.connect(executeAfterSelection).
Then try to select features in the layer.
You will see the function executeAfterSelection is execute three times after each selection.

I have done an workaround by introducing a flag variable which tells me if the myLayer.selectionChanged.connect(executeAfterSelection) statement was already called.

Thanks,
Marian

From: Qgis-user [mailto:qgis-user-bounces at lists.osgeo.org] On Behalf Of Matthias Kuhn
Sent: October-03-17 3:13 AM
To: qgis-user at lists.osgeo.org
Subject: Re: [Qgis-user] Check if a selectionChanged signal is connected to any slot?


Hi Marian,

Just tell Qt that it shouldn't create the connection more than once using Qt::UniqueConnection.

Cheers

Matthias

On 10/2/17 5:30 PM, Tudorache, Marian wrote:

Hi everyone,

I have connected the signal selectionChanged so some code, which is executed after features are selected.

myLayer.selectionChanged.connect(self.executeAfterSelection)

Then I have a method self. executeAfterSelection(self, featuresIds)

The SIGNAl/SLOT tandem works but now I realized every time when I call myLayer.selectionChanged.connect(self.executeAfterSelection)  It does not overwrite my previous call. It creates a second signa/slot tandem. During running the method  executeAfterSelection is excuted twice, three times etc.

How can I check if the SIGNAL selectionChanged is connected to the slot executeAfterSelection before I run myLayer.selectionChanged.connect(self.executeAfterSelection)?

I tried this:
receiversCount = QtCore.QObject.receivers(QtCore.SIGNAL("selectionChanged()")
receiversCount = QtCore.QObject.receivers(QtCore.SIGNAL("selectionChanged")
receiversCount = QtCore.QObject.receivers(QtCore.SIGNAL("myLayer.selectionChanged()")
receiversCount = QtCore.QObject.receivers(QtCore.SIGNAL("myLayer.selectionChanged")

Every time I get this error:

QObject.receivers(SIGNAL()): first argument of unbound method must have type 'QObject').


Thanks,
Marian




________________________________

This electronic message, as well as any transmitted files included in the electronic message, may contain privileged or confidential information and is intended solely for the use of the individual(s) or entity to which it is addressed. If you have received this electronic message in error please notify the sender immediately and delete the electronic message. Any unauthorized copying, disclosure or distribution of the electronic message is strictly forbidden. NAV CANADA accepts no liability for any damage caused by any virus and/or other malicious code transmitted by this electronic communication.

Le présent message électronique et tout fichier qui peut y être joint peuvent contenir des renseignements privilégiés ou confidentiels destinés à l'usage exclusif des personnes ou des organismes à qui ils s'adressent. Si vous avez reçu ce message électronique par erreur, veuillez en informer l'expéditeur immédiatement et supprimez le. Toute reproduction, divulgation ou distribution du présent message électronique est strictement interdite. NAV CANADA n'assume aucune responsabilité en cas de dommage causé par tout virus ou autre programme malveillant transmis par ce message électronique.




_______________________________________________

Qgis-user mailing list

Qgis-user at lists.osgeo.org<mailto:Qgis-user at lists.osgeo.org>

List info: https://lists.osgeo.org/mailman/listinfo/qgis-user

Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20171003/6c0548f4/attachment.html>


More information about the Qgis-user mailing list