<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); "><div style="font-size: 14px; font-family: Calibri, sans-serif; ">Hi All,</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; ">So, to answer my own question, this seg fault only occurs when the shortcuts context is set as a property (i.e. a keyword argument) on instantiation. Its fine if you do it afterwards via the appropriate setter method, so my little example program would go as follows:</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div><div><font face="Consolas" style="font-size: 10px;">import sip</font></div><div><font face="Consolas" style="font-size: 10px;">sip.setapi('QString',2)</font></div><div><font face="Consolas" style="font-size: 10px;">sip.setapi('QVariant',2)</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">from PyQt4.QtCore import *</font></div><div><font face="Consolas" style="font-size: 10px;">from PyQt4.QtGui import *</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">class Widget(QWidget):</font></div><div><font face="Consolas" style="font-size: 10px;"> def __init__(self, parent=None, **kwargs):</font></div><div><font face="Consolas" style="font-size: 10px;"> QWidget.__init__(self, parent, **kwargs)</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> self.shortcut=QShortcut(</font></div><div><font face="Consolas" style="font-size: 10px;"> QKeySequence("Alt+1"),</font></div><div><font face="Consolas" style="font-size: 10px;"> self,</font></div><div><font face="Consolas" style="font-size: 10px;"> activated=self._sca</font></div><div><font face="Consolas" style="font-size: 10px;"> )</font></div><div><font face="Consolas" style="font-size: 10px;"> self.shortcut.setContext(Qt.ApplicationShortcut)</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> @pyqtSlot()</font></div><div><font face="Consolas" style="font-size: 10px;"> def _sca(self): print "SCA"</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">if __name__=="__main__":</font></div><div><font face="Consolas" style="font-size: 10px;"> from sys import argv, exit</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> a=QApplication(argv)</font></div><div><font face="Consolas" style="font-size: 10px;"> w=Widget()</font></div><div><font face="Consolas" style="font-size: 10px;"> w.show()</font></div><div><font face="Consolas" style="font-size: 10px;"> w.raise_()</font></div><div><font face="Consolas" style="font-size: 10px;"> exit(a.exec_())</font></div></div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; ">Sorry for the inbox spam folks, Rob</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><span id="OLK_SRC_BODY_SECTION" style="font-size: 14px; font-family: Calibri, sans-serif; "><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> Robert Kent <<a href="mailto:rob@gulon.co.uk">rob@gulon.co.uk</a>><br><span style="font-weight:bold">Date: </span> Thursday, 30 October 2014 13:42<br><span style="font-weight:bold">To: </span> pyqt <<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>><br><span style="font-weight:bold">Subject: </span> [PyQt] QShortcut causes seg fault with non-widget context<br></div><div><br></div><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); "><div style="font-size: 14px; font-family: Calibri, sans-serif; ">Hi All,</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; ">I'm trying to use QShortcut to set a global shortcut for my application, however if I set the context to anything other than Qt.WidgetContext (I.e. Qt.ApplicationContext in my case) the application crashes. This behaviour is true for Mac OSX 10.8 and Windows 7. I'm using Python 2.7.2, Qt4.8 and PyQt4.10. The following little program is a demo and crashes for me:</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div><div><font face="Consolas" style="font-size: 10px;">import sip</font></div><div><font face="Consolas" style="font-size: 10px;">sip.setapi('QString',2)</font></div><div><font face="Consolas" style="font-size: 10px;">sip.setapi('QVariant',2)</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">from PyQt4.QtCore import *</font></div><div><font face="Consolas" style="font-size: 10px;">from PyQt4.QtGui import *</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">class Widget(QWidget):</font></div><div><font face="Consolas" style="font-size: 10px;"> def __init__(self, parent=None, **kwargs):</font></div><div><font face="Consolas" style="font-size: 10px;"> QWidget.__init__(self, parent, **kwargs)</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> self.shortcut=QShortcut(</font></div><div><font face="Consolas" style="font-size: 10px;"> "Ctrl+P",</font></div><div><font face="Consolas" style="font-size: 10px;"> self,</font></div><div><font face="Consolas" style="font-size: 10px;"> context=Qt.ApplicationShortcut,</font></div><div><font face="Consolas" style="font-size: 10px;"> activated=self._sca</font></div><div><font face="Consolas" style="font-size: 10px;"> )</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> @pyqtSlot()</font></div><div><font face="Consolas" style="font-size: 10px;"> def _sca(self): print "SCA"</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;">if __name__=="__main__":</font></div><div><font face="Consolas" style="font-size: 10px;"> from sys import argv, exit</font></div><div><font face="Consolas" style="font-size: 10px;"><br></font></div><div><font face="Consolas" style="font-size: 10px;"> a=QApplication(argv)</font></div><div><font face="Consolas" style="font-size: 10px;"> w=Widget()</font></div><div><font face="Consolas" style="font-size: 10px;"> w.show()</font></div><div><font face="Consolas" style="font-size: 10px;"> w.raise_()</font></div><div><font face="Consolas" style="font-size: 10px;"> exit(a.exec_())</font></div></div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; ">Just wondering if anybody has had this issue and can tell me what I'm doing wrong or if this is a genuine bug.</div><div style="font-size: 14px; font-family: Calibri, sans-serif; "><br></div><div style="font-size: 14px; font-family: Calibri, sans-serif; ">Thanks very much, Rob</div></div></div>
_______________________________________________
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></span></body></html>