I am creating a Plugin, where on addFeature button, first user will get a dialog box to select the type of feature user wants to draw. On the basis of users choice, other editing constraints will get activated as defined for a layer. Currently I am able to create a dialog box with radio buttons for users selection and things are working correctly for first run, if user is following below steps in order.

  1. Start editing (Toggle Editing)
  2. Add Feature button
  3. Dialog box for users choice
  4. Editing by the user as per applied constraints
  5. Stop Editing (Toggle Editing)

The above steps are working fine for first run, but if user starts another editing session, then the dialog box is getting for 2 times and so on for further sessions.

While working on this, I found layer.editingStarted.connect(function), this signal is getting continued even after complete execution of function. I tried to disconnect this but not able to do it.

How can I disconnect the same or is there any other workaround for this problem?

My Code and Dialog box are attached for reference.

def fiber_add_feature(self,db,vlyr):
    if vlyr.name()=="Fiber Cable":
        iface.actionAddFeature().triggered.connect(lambda: self.fiber_route_type(db,vlyr))
def fiber_route_type(self,db,lyr):
    if lyr.name()=="Fiber Cable":
        if lyr.isEditable():
            ugr="Under Ground Route"
            route_result = self.route_dlg.exec_()
            if route_result:
                if self.route_dlg.ar_rb.isChecked():
                    fiber = fiberEditTool(self.canvas, self.iface,db,ar, not(Duct_presnt))
                elif self.route_dlg.ugr_rb.isChecked():
                    duct_result = self.duct_require_dlg.exec_()
                    if duct_result:
                        if self.duct_require_dlg.cb_duct.isChecked():
                            fiber = fiberEditTool(self.canvas, self.iface,db,ugr,Duct_presnt)
                        elif self.duct_require_dlg.cb_wo_duct.isChecked():
                            fiber = fiberEditTool(self.canvas, self.iface,db,ugr,not(Duct_presnt))

enter image description here

  • Couldn't you just execute the iface.actionAddFeature().triggered.connect(...) line in the initGui() of your plugin? Or perhaps just discard the 2nd and 3rd lines of your script above? Jul 3, 2020 at 13:02
  • @GermánCarrillo, I tried with iface.actionAddFeature().triggered.connect(...), the problem with this command is, it is getting triggered at all layers not on the particular layer for which editing constraints are defined. This is the reason, i am writing lyr.editingStarted.connect(...), just to call the action on the particular active layer. Jul 4, 2020 at 10:28
  • Yes, but you could go for your specific layer using its name: gis.stackexchange.com/questions/136861/… and only set the connection for that specific layer. Jul 4, 2020 at 13:08
  • Correct, In the code, I mentioned same condition for layer on layer name (vlyr.name()=="Fiber Cable") but iface.actionAddFeature().triggered.connect(...), it is getting triggered irrespective of layer name if i write it outside the other function without lyr.editingStarted.connect(...). Jul 4, 2020 at 13:20

1 Answer 1


While doing some research for above question, I found some details to stop editingStarted signal with following code.

    if layer.name()=="Fiber":
    def first_method():
        if layer.isEditable():
            print("In first method")
               print("editingStarted signal is not disconnected")
               print("editingStopped signal is not disconnected")

Things are working fine for single layer, but if I have multiple layers in project and I start and stop editing for other layer and again start editing for my required layer at then QGIS is not starting editing for my required layer.

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.