[PyQt] Bug in QAbstractNativeEventFilter in PyQt 5.1.1?
Phil Thompson
phil at riverbankcomputing.com
Tue Dec 10 10:37:16 GMT 2013
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
More information about the PyQt
mailing list