<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div>
<p>I get a strange behavior that's happening on OSX but not on Windows.</p>
<p>I made a software with pyqt5 and when I close a child window I have a crash with "Segmentation fault: 11"
</p>
<p>To explain better, I have a main window where I may open other windows to ask to the user some info. the error is happening when I close that second window.</p>
<p>I have a <code>closeEvent</code> function : </p>
<pre><code><span> def</span><span> closeEvent</span><span>(</span><span>self</span><span>,</span><span> event</span><span>):</span><span>
self</span><span>.</span><span>Close_OBJ</span><span>.</span><span>emit</span><span>()</span><span>
self</span><span>.</span><span>close</span><span>()</span></code></pre>
<p>which send a <code>pyqtSignal</code>to the main window.</p>
<p>If I comment the <code>self.Close_OBJ.emit()</code>I don't have the Segmentation fault anymore, but I need this so my main window can react to the closing of that child window.</p>
<p>What is also confusing is that I have other child windows where I have the same
<code>closeEvent</code> function and it's work well. I don't understand why I don't have this issue on Windows OS.</p>
<p>Here's a minimal example of the issue:</p>
<pre><code><span>from</span><span> </span><span>PyQt5</span><span>.</span><span>QtGui</span><span> </span><span>import</span><span> </span><span>*</span><span>
</span><span>from</span><span> </span><span>PyQt5</span><span>.</span><span>QtWidgets</span><span> </span><span>import</span><span> </span><span>*</span><span>
</span><span>from</span><span> </span><span>PyQt5</span><span>.</span><span>QtCore</span><span> </span><span>import</span><span> </span><span>*</span><span>
</span><span>import</span><span> sys
</span><span>class</span><span> </span><span>Modify_1_NMM</span><span>(</span><span>QMainWindow</span><span>):</span><span>
</span><span>Close_OBJ</span><span> </span><span>=</span><span> pyqtSignal</span><span>()</span><span>
</span><span>def</span><span> __init__</span><span>(</span><span>self</span><span>,):</span><span>
super</span><span>(</span><span>Modify_1_NMM</span><span>,</span><span> self</span><span>).</span><span>__init__</span><span>()</span><span>
self</span><span>.</span><span>centralWidget </span><span>=</span><span> </span><span>QWidget</span><span>()</span><span>
self</span><span>.</span><span>setCentralWidget</span><span>(</span><span>self</span><span>.</span><span>centralWidget</span><span>)</span><span>
self</span><span>.</span><span>mainHBOX_param_scene </span><span>=</span><span> </span><span>QHBoxLayout</span><span>()</span><span>
self</span><span>.</span><span>label </span><span>=</span><span> </span><span>QLabel</span><span>(</span><span>'Please, close this window'</span><span>)</span><span>
self</span><span>.</span><span>mainHBOX_param_scene</span><span>.</span><span>addWidget</span><span>(</span><span>self</span><span>.</span><span>label</span><span>)</span><span>
self</span><span>.</span><span>centralWidget</span><span>.</span><span>setLayout</span><span>(</span><span>self</span><span>.</span><span>mainHBOX_param_scene</span><span>)</span><span>
</span><span>def</span><span> closeEvent</span><span>(</span><span>self</span><span>,</span><span> event</span><span>):</span><span>
self</span><span>.</span><span>Close_OBJ</span><span>.</span><span>emit</span><span>()</span><span>
self</span><span>.</span><span>close</span><span>()</span><span>
</span><span>class</span><span> </span><span>StimEdit</span><span>(</span><span>QMainWindow</span><span>):</span><span>
</span><span>def</span><span> __init__</span><span>(</span><span>self</span><span>,</span><span> parent</span><span>=</span><span>None</span><span>):</span><span>
super</span><span>(</span><span>StimEdit</span><span>,</span><span> self</span><span>).</span><span>__init__</span><span>()</span><span>
self</span><span>.</span><span>NewModifyXNMM</span><span> </span><span>=</span><span> </span><span>None</span><span>
self</span><span>.</span><span>centralWidget </span><span>=</span><span> </span><span>QWidget</span><span>()</span><span>
self</span><span>.</span><span>setCentralWidget</span><span>(</span><span>self</span><span>.</span><span>centralWidget</span><span>)</span><span>
self</span><span>.</span><span>mainHBOX_param_scene </span><span>=</span><span> </span><span>QHBoxLayout</span><span>()</span><span>
self</span><span>.</span><span>B </span><span>=</span><span> </span><span>QPushButton</span><span>(</span><span>'clik here to open o window'</span><span>)</span><span>
self</span><span>.</span><span>B</span><span>.</span><span>setFixedSize</span><span>(</span><span>400</span><span>,</span><span>200</span><span>)</span><span>
self</span><span>.</span><span>B</span><span>.</span><span>clicked</span><span>.</span><span>connect</span><span>(</span><span>self</span><span>.</span><span>ModXNMMclicked</span><span>)</span><span>
self</span><span>.</span><span>mainHBOX_param_scene</span><span>.</span><span>addWidget</span><span>(</span><span>self</span><span>.</span><span>B</span><span>)</span><span>
self</span><span>.</span><span>centralWidget</span><span>.</span><span>setLayout</span><span>(</span><span>self</span><span>.</span><span>mainHBOX_param_scene</span><span>)</span><span>
</span><span>def</span><span> </span><span>ModXNMMclicked</span><span>(</span><span>self</span><span>,):</span><span>
</span><span>if</span><span> self</span><span>.</span><span>NewModifyXNMM</span><span> </span><span>==</span><span> </span><span>None</span><span>:</span><span>
self</span><span>.</span><span>NewModifyXNMM</span><span> </span><span>=</span><span> </span><span>Modify_1_NMM</span><span>()</span><span>
self</span><span>.</span><span>NewModifyXNMM</span><span>.</span><span>Close_OBJ</span><span>.</span><span>connect</span><span>(</span><span>self</span><span>.</span><span>close_ModXNMM</span><span>)</span><span>
self</span><span>.</span><span>NewModifyXNMM</span><span>.</span><span>show</span><span>()</span><span>
</span><span>@pyqtSlot</span><span>()</span><span>
</span><span>def</span><span> close_ModXNMM</span><span>(</span><span>self</span><span>):</span><span>
</span><span>print</span><span>(</span><span>'about to close'</span><span>,</span><span>self</span><span>)</span><span>
self</span><span>.</span><span>NewModifyXNMM</span><span> </span><span>=</span><span> </span><span>None</span><span>
</span><span>print</span><span>(</span><span>'did closed'</span><span>)</span><span>
</span><span>def</span><span> main</span><span>():</span><span>
app </span><span>=</span><span> </span><span>QApplication</span><span>(</span><span>sys</span><span>.</span><span>argv</span><span>)</span><span>
ex </span><span>=</span><span> </span><span>StimEdit</span><span>(</span><span>app</span><span>)</span><span>
ex</span><span>.</span><span>show</span><span>()</span><span>
sys</span><span>.</span><span>exit</span><span>(</span><span>app</span><span>.</span><span>exec_</span><span>(</span><span> </span><span>))</span><span>
</span><span>if</span><span> __name__ </span><span>==</span><span> </span><span>'__main__'</span><span>:</span><span>
main</span><span>()</span></code></pre>
<p>when I click on the button on the main window, a second window opens. When I then close the second window, it crashes (not even all the time... but most of the time).</p>
<p>On pycharm I get this error message :</p>
<pre><code><span>about to close </span><span><</span><span>__main__</span><span>.</span><span>StimEdit</span><span> object at </span><span>0x103f0af78</span><span>></span><span>
did closed
</span><span>Process</span><span> finished </span><span>with</span><span> exit code </span><span>139</span><span> </span><span>(</span><span>interrupted by signal </span><span>11</span><span>:</span><span> SIGSEGV</span><span>)</span></code></pre>
<p>and on the terminal I get: </p>
<pre><code><span>about to close </span><span><</span><span>__main__</span><span>.</span><span>StimEdit</span><span> object at </span><span>0x10c706288</span><span>></span><span>
did closed
</span><span>Segmentation</span><span> fault</span><span>:</span><span> </span><span>11</span></code></pre>
</div>
<br>
</div>
</body>
</html>