# Use of qt.Signal leads to a crash on exit

**URL:** <https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321>\
**Category:** Development\
**Created:** [September 6, 2019, 12:16pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321 "2019-09-06T12:16:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 6, 2019, 12:16pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/1 "2019-09-06T12:16:54Z")

</div>

Recently, I have been investigating the source of a crash on exit.

To reproduce the crash:

```auto
./Slicer --no-main-window --testing

```

Notes:

- removing the connection to the `closed` signal object [here](https://github.com/Slicer/Slicer/blob/45cf7d262fc07078fa94ece66520b0ac58f321d7/Modules/Scripted/DICOM/DICOM.py#L153) in the DICOM module avoids the crash on exit from happening.
- disconnecting the signal on exit (or just after setting the connection) does **not** prevent the crash from happening
- starting the application with the main window prevents the crash on exit from happening
- a possibly related thread on the PythonQt forum is this one: [Segmentation fault after emiting a signal](https://sourceforge.net/p/pythonqt/discussion/631393/thread/bbc98b8f/)
- yesterday, we updated (see [r28485](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=28485)) to use the latest version of PythonQt thinking the issue would be addressed … but it is not.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 6, 2019, 12:25pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/2 "2019-09-06T12:25:15Z")

</div>

Create a script `test.py` with the following content:

```python
class FooDetailsWidget(qt.QWidget):
  closed = qt.Signal() # Invoked when the dicom widget is closed using the close method
  def __init__ (self):
    qt.QWidget. __init__ (self)

class Foo(object):
  def __init__ (self):
    self.detailsPopup = FooDetailsWidget()
    self.detailsPopup.closed.connect(self.onDetailsPopupClosed)
  def onDetailsPopupClosed(self):
    print("onDetailsPopupClosed")

d = Foo()
d.detailsPopup.closed.emit()

# In this case, disconnecting prevent the crash on exit from happening
# d.detailsPopup.closed.disconnect(d.onDetailsPopupClosed)

```

and running Slicer with the following allows to reproduce a crash on exit. But:

- the condition are not exactly the same
- disconnecting the signal prevent the crash from happening whereas in the `DICOM` module it does **not**
- with/without `--no-main-window` lead to a crash

```auto
./Slicer --disable-modules --no-main-window --testing --python-script /tmp/test.py

```

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [June 4, 2020, 2:41pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/3 "2020-06-04T14:41:52Z")

</div>

Hi jcfr, have you solved this? The pythonQt seems to not support calling emit() directly. Do you have a workaround? Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 4, 2020, 3:05pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/4 "2020-06-04T15:05:55Z")

</div>

Would you like to emit another object’s _signal_? This was explicitly prohibited in Qt4 but to allow new syntax in Qt5 this cannot be prevented anymore. Still, it should not be done, as you would essentially lie about the internal state of the other object to all connected objects. Objects should always emit their own signals only. Objects can call other object’s _slots_.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [December 26, 2023, 4:36pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/5 "2023-12-26T16:36:55Z")

</div>

Dear all,  
I dig up this thread but I think it is worth having a solution to this issue.  
I am exactly in the same situation as @jcfr : I have a widget in python that emits signals and the moment I connect to these signal in another widget, I have this silent crash on exit, even if disconnection are properly implemented. I have tried several modifications without managing to find a good solution.  
@jcfr have you explored a bit further this issue ?  
Thanks for your input

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 30, 2023, 1:58pm UTC](https://discourse.slicer.org/t/use-of-qt-signal-leads-to-a-crash-on-exit/8321/6 "2023-12-30T13:58:42Z")

</div>

> [@riep](#):
>
> have a widget in python that emits signals

Does the widget emit its own signal, or the tries to make make another object emit a signal? Can you provide a minimal reproducible example script?
