[PyQt] Bug in QAbstractNativeEventFilter in PyQt 5.1.1?

Klemetti, Antti antti.klemetti at f-secure.com
Tue Dec 10 12:19:53 GMT 2013


Hi,

You missed my point. 
If I return anything else than None (includes int values likes 0 and 1 and so on), 
the application using PyQt5 crashes.
By returning None, I can avoid the crash, but I understand that I should return an int.
Please try it yourself.

BR, Antti
________________________________________
From: pyqt-bounces at riverbankcomputing.com [pyqt-bounces at riverbankcomputing.com] On Behalf Of Phil Thompson [phil at riverbankcomputing.com]
Sent: Tuesday, December 10, 2013 12:37 PM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] Bug in QAbstractNativeEventFilter in PyQt 5.1.1?

On 10-12-2013 8:52 am, Klemetti, Antti wrote:
> Hi,
>
> Our application subclasses QAbstractNativeEventFilter and
> reimplements function QAbstractNativeEventFilter.nativeEventFilter
> to catch application specific messages on Windows.
> The Python version used is 3.3.2.
>
> It seems that the PyQt implementation of
> QAbstractNativeEventFilter.nativeEventFilter
> has a slightly modified function signature from that of Qt5 C++.
> The Qt5 C++ function takes three parameters: eventType, message and
> result.
> The PyQt version takes two parameters: eventType, message as input
> and
> returns a tuple of bool and int, where int is the result.
>
> The modified signature is not a problem, but there is some bug in the
> PyQt5 implementation.
> If I return anything else than None as the result from my
> nativeEventFilter function,
> PyQt5 implementation crashes.
> If I return None, stderr gets the following error message:
> "TypeError: invalid result type from
> WinEventFilter.nativeEventFilter()".
>
> Here is our subclass implementation:
> -----
>     class WinEventFilter(QAbstractNativeEventFilter):
>         def __init__(self, my_windows_message, log):
>             QAbstractNativeEventFilter.__init__(self)
>             self.my_windows_message = my_windows_message
>             self.log = log
>
>         def nativeEventFilter(self, eventType, message): # pylint:
> disable=W0613
>             try:
>                 msg =
> ctypes.wintypes.MSG.from_address(message.__int__()) # pylint:
> disable=E1101
>                 if msg.message == self.my_windows_message:
>                     # Handling for our special Windows message
>                     pass
>             except:
>                 self.log.exception("Exception in
> WinEventFilter.nativeEventFilter")
>             dummy_result = None
>             return False, dummy_result # False lets the event
> propagate freely

Return an int instead of None.

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


More information about the PyQt mailing list