Connecting widget callback with custom logic signal/event in a scripted module

Hi,
I’m trying to connect a callback in the widget class of my scripted module with a custom event of the logic class. My first attempt has been with the Qt signal/slot system, much like in this post.

My code looks like so:

class MyModuleWidget(ScriptedLoadableModuleWidget, VTKObservationMixin):
  def setup(self):
    ...
    self.logic.moved.connect(self.onPtrMoved)

  def onPtrMoved(self):
    # do something

class MyModuleLogic(ScriptedLoadableModuleLogic):
  def __init__(self):
    ...
    self.moved = qt.Signal()
  
  @vtk.calldata_type(vtk.VTK_OBJECT)
  def someOtherCallback(self, caller, event=None, calldata=None):
    self.moved.emit()

When someOtherCallback is called, the signal is allegedly emitted and then Slicer crashes.

I would like to know why it’s not working given that the signal is emitted from its own class (which is better as pointed out here) and how to fix it. Also, I’m not restricted to using Qt for this and apparently resorting to a vtk custom event and an observer would be a better way (as suggested here) but I couldn’t find any example in Python.

Any help would be appreciated

MRML classes (such as the module logic classes) do not depend on Qt, to minimize unnecessary dependencies. Therefore, you cannot emit Qt signals from logic classes. Instead, you can use VTK events and callbacks.

Widgets normally do not observe logic classes, because logic classes are generally stateless. State is stored in MRML nodes instead, the logic classes may modifies MRML nodes (such as the scripted module’s parameter node; or any other nodes), and widgets observe MRML node changes. You can define your own event IDs (just choose numbers that are not used already on that object) and invoke them on any MRML node.