I have this function with: self.iface.mapCanvas().selectionChanged.connect(self.openThePano)

which waits for a feature selection change to connect to the function openThePano the issue is that once a single feature is selected the function is called twice and there is only one line that has this signal.

example code:

def actualapp(self):
    #waits for the signal

def openThePano(self,fId):
    #gets the feature's attributes
    featget = fId.selectedFeatures()
    atributos = [i.attributes() for i in featget]

    source = ogr.Open(self.shproute)
    layer = source.GetLayer() 
    schema = [] 
    ldef = layer.GetLayerDefn()
    for n in range(ldef.GetFieldCount()): # gets the attributes' names
        fdef = ldef.GetFieldDefn(n)

    # This loop prints attributes of the selected feature and is being printed twice.
    for i in range(len(atributos[0])): 
        print('{}: {}'.format(str(schema[i]),str(atributos[0][i])))


I expect it to only print once the list of attributes but for some reason I ignore it does it twice, any ideas?


I had the same issue in the past : i think the signal is triggered when the selection changes that means (if u make one by one feature selections ...) that the signal is triggered when your previous feature is deselected AND your next feature is selected ...

The case of multiple feature selection must be handled by your code too ...

See link and api doc of course ...

  • I am not sure I understand, I saw docs and your post, you are saying that it is being printed twice because it is calling both signals, the deselection and the selection? I also saw a Parameter called "clearAndSelect" but I am not sure how to call it because it tells me that doesn't exist. @snaileater – Thriskel May 16 at 13:20
  • tried this out: self.iface.mapCanvas().selectionChanged(clearAndSelect=True).connect(self.openThePano) and gave native Qt Signal is not callable I would appreciate any help you could provide. – Thriskel May 16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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