[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QShortcut causes seg fault with non-widget context
From:       Robert Kent <rob () gulon ! co ! uk>
Date:       2014-10-30 16:03:23
Message-ID: D0781111.4A57%rob () gulon ! co ! uk
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi All,

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:

import sip
sip.setapi('QString',2)
sip.setapi('QVariant',2)

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Widget(QWidget):
    def __init__(self, parent=None, **kwargs):
        QWidget.__init__(self, parent, **kwargs)

        self.shortcut=QShortcut(
            QKeySequence("Alt+1"),
            self,
            activated=self._sca
        )
        self.shortcut.setContext(Qt.ApplicationShortcut)

    @pyqtSlot()
    def _sca(self): print "SCA"

if __name__=="__main__":
    from sys import argv, exit

    a=QApplication(argv)
    w=Widget()
    w.show()
    w.raise_()
    exit(a.exec_())

Sorry for the inbox spam folks, Rob

From:  Robert Kent <rob@gulon.co.uk>
Date:  Thursday, 30 October 2014 13:42
To:  pyqt <pyqt@riverbankcomputing.com>
Subject:  [PyQt] QShortcut causes seg fault with non-widget context

Hi All,

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:

import sip
sip.setapi('QString',2)
sip.setapi('QVariant',2)

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Widget(QWidget):
    def __init__(self, parent=None, **kwargs):
        QWidget.__init__(self, parent, **kwargs)

        self.shortcut=QShortcut(
            "Ctrl+P",
            self,
            context=Qt.ApplicationShortcut,
            activated=self._sca
        )

    @pyqtSlot()
    def _sca(self): print "SCA"

if __name__=="__main__":
    from sys import argv, exit

    a=QApplication(argv)
    w=Widget()
    w.show()
    w.raise_()
    exit(a.exec_())

Just wondering if anybody has had this issue and can tell me what I'm doing
wrong or if this is a genuine bug.

Thanks very much, Rob
_______________________________________________ PyQt mailing list
PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[Attachment #5 (text/html)]

<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;">&nbsp; &nbsp; def __init__(self, parent=None, \
**kwargs):</font></div><div><font face="Consolas" style="font-size: 10px;">&nbsp; \
&nbsp; &nbsp; &nbsp; 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;">&nbsp; &nbsp; &nbsp; &nbsp; \
self.shortcut=QShortcut(</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
QKeySequence("Alt+1"),</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self,</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
activated=self._sca</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; &nbsp; &nbsp; )</font></div><div><font face="Consolas" \
style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; \
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;">&nbsp; &nbsp; @pyqtSlot()</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; 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;">&nbsp; &nbsp; 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;">&nbsp; &nbsp; a=QApplication(argv)</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; \
w=Widget()</font></div><div><font face="Consolas" style="font-size: 10px;">&nbsp; \
&nbsp; w.show()</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; w.raise_()</font></div><div><font face="Consolas" \
style="font-size: 10px;">&nbsp; &nbsp; 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 &lt;<a \
href="mailto:rob@gulon.co.uk">rob@gulon.co.uk</a>&gt;<br><span \
style="font-weight:bold">Date: </span> Thursday, 30 October 2014 13:42<br><span \
style="font-weight:bold">To: </span> pyqt &lt;<a \
href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>&gt;<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;">&nbsp; &nbsp; def __init__(self, parent=None, \
**kwargs):</font></div><div><font face="Consolas" style="font-size: 10px;">&nbsp; \
&nbsp; &nbsp; &nbsp; 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;">&nbsp; &nbsp; &nbsp; &nbsp; \
self.shortcut=QShortcut(</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Ctrl+P",</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
self,</font></div><div><font face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; context=Qt.ApplicationShortcut,</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
activated=self._sca</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; &nbsp; &nbsp; )</font></div><div><font face="Consolas" \
style="font-size: 10px;"><br></font></div><div><font face="Consolas" \
style="font-size: 10px;">&nbsp; &nbsp; @pyqtSlot()</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; 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;">&nbsp; &nbsp; 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;">&nbsp; &nbsp; a=QApplication(argv)</font></div><div><font \
face="Consolas" style="font-size: 10px;">&nbsp; &nbsp; \
w=Widget()</font></div><div><font face="Consolas" style="font-size: 10px;">&nbsp; \
&nbsp; w.show()</font></div><div><font face="Consolas" style="font-size: \
10px;">&nbsp; &nbsp; w.raise_()</font></div><div><font face="Consolas" \
style="font-size: 10px;">&nbsp; &nbsp; 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>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic