Will signals automatically disconnect, when target object is destroyed? Without recording the signal id from g_signal_connect()
, can I remove that signal?
Asked
Active
Viewed 1.3k times
3 Answers
18
If you didn't save the signal handler ID, you can search for it using g_signal_handler_find()
and disconnect it the usual way, or disconnect any signals that match certain criteria with g_signal_handlers_disconnect_matched()
or g_signal_handlers_disconnect_by_func()
.

ptomato
- 56,175
- 13
- 112
- 165
10
Of course when the target object is destroyed, the signals connected to it are removed (otherwise there would be a massive memory leak, but read the warning on g_signal_connect_object). However, to call g_signal_handler_disconnect you need the handler id given by g_signal_connect
and friends.

Fabio says Reinstate Monica
- 5,271
- 9
- 40
- 61

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
1
You can use the *handler_block_by_func* and *handler_unblock_by_func* methods.
Example (PyGTK):
def on_treeview_fixedexpenses_cursor_changed(self, widget):
self.checkbutton_fixedexpensetax.handler_block_by_func(self.on_checkbutton_fixedexpensetax_toggled)
self.updateCurrentFixedExpense()
self.checkbutton_fixedexpensetax.handler_unblock_by_func(self.on_checkbutton_fixedexpensetax_toggled)
Source: http://www.pygtk.org/docs/pygobject/class-gobject.html

Jesus
- 26
- 6
-
2It is unclear for me what your code does and how does it answer the question. Can you explain it a bit more please. – buhtz Feb 15 '19 at 11:07