Repository: spyder-ide/spyder

Issue:
Segmentation fault when trying to change keyboard shortcuts in Preferences
## Description of your problem
There is a segmentation dump issue and spyder is getting crashed whenever I tried to change the default key combination for comment in Spyder. [Ubuntu]
**What steps will reproduce the problem?**
1. Launch and go to preferences
2. Click on the keyboard shortcuts and try to change it.
3. Segmentation dump issue in Ubuntu

**What is the expected output? What do you see instead?**
No crash. changes should be successful.

**Please provide any additional information below**


## Versions and main components

* Spyder Version: 3.2.3
* Python Version: 3.6.2
* Qt Version:
* PyQt Version:
* Operating system: Ububtu


## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:



Discussion:
What are your Qt and PyQt versions?
Also, please run in a terminal

    spyder --reset

and try again
I'm using Ubuntu 16.04 as well and I get the segmentation fault if I open any keyboard shortcut window, even if I click the Cancel button without making any changes.

I don't know if it's helpful, but I ran gdb and recreated the error:
> Thread 1 "python" received signal SIGSEGV, Segmentation fault.
> 0x00007ffff2c0816e in QMetaObject::activate(QObject*, int, int, void**) ()
>  from /home/cheryl/anaconda3/envs/spyder-dev/lib/python3.6/site-packages/PyQt5/../../../libQt5Core.so.5
 

As I said before, what are your Qt and PyQt versions?

El 09/10/17 a las 16:31, Cheryl Sabella escribió:
>
> I'm using Ubuntu 16.04 as well and I get the segmentation fault if I 
> open any keyboard shortcut window, even if I click the Cancel button 
> without making any changes.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub 
> <https://github.com/spyder-ide/spyder/issues/5426#issuecomment-335296445>, 
> or mute the thread 
> <https://github.com/notifications/unsubscribe-auth/AAWS7VMKhxwlhmnTAuK193JL7M5StVBpks5sqpDFgaJpZM4PyNGG>.
>


Sorry, I wasn't trying to report a bug, just trying to help provide debugging information.  But, here are my versions:
[Python 3.6.3 64bits, Qt 5.6.2, PyQt5 5.6 on Linux]
Thanks @csabella!
@csabella, is this still an issue for you?
@ccordoba12   It still happens on 3.x, but does not happen on master.
I can't reproduce this in Kubuntu 17.04.
On the last update, I said it wasn't happening on master, but now it's happening on master for me, as well as 3.x and the release version of 3.2.5.

I open Preferences, then Keyboard Shortcuts, double click on 'Find Next/F3', press F4 for the new shortcut, and click OK.  It closes Spyder and gives a seg fault.  I looked at this a little bit when it was first reported, but I'm going to spend some more time on it now to try to track it down.
Thanks Cheryl! I don't think this is going to be easy to fix...

Resolving patch:
diff --git a/spyder/plugins/shortcuts.py b/spyder/plugins/shortcuts.py
--- a/spyder/plugins/shortcuts.py
+++ b/spyder/plugins/shortcuts.py
@@ -16,7 +16,7 @@
 from qtpy import PYQT5
 from qtpy.compat import from_qvariant, to_qvariant
 from qtpy.QtCore import (QAbstractTableModel, QModelIndex, QRegExp,
-                         QSortFilterProxyModel, Qt)
+                         QSortFilterProxyModel, Qt, Slot)
 from qtpy.QtGui import (QKeySequence, QRegExpValidator)
 from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog,
                             QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel,
@@ -204,6 +204,24 @@ def __init__(self, parent, context, name, sequence, shortcuts):
         bbox.accepted.connect(self.accept)
         bbox.rejected.connect(self.reject)
 
+    @Slot()
+    def reject(self):
+        """Slot for rejected signal."""
+        # Added for issue #5426.  Due to the focusPolicy of Qt.NoFocus for the
+        # buttons, if the cancel button was clicked without first setting focus
+        # to the button, it would cause a seg fault crash.
+        self.button_cancel.setFocus()
+        super().reject()
+
+    @Slot()
+    def accept(self):
+        """Slot for accepted signal."""
+        # Added for issue #5426.  Due to the focusPolicy of Qt.NoFocus for the
+        # buttons, if the ok button was clicked without first setting focus to
+        # the button, it would cause a seg fault crash.
+        self.button_ok.setFocus()
+        super().accept()
+
     def keyPressEvent(self, e):
         """Qt override."""
         key = e.key()


Test patch: