[PyQt] How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson phil at riverbankcomputing.com
Tue Jan 31 13:06:13 GMT 2017


On 31 Jan 2017, at 12:39 pm, slepton at posteo.de wrote:
> 
> Hi Phil
> 
> unfortunaly it didn't work. A minimal example of what I am doing (wrong):
> 
> 
> import ctypes
> import win32event
> from PyQt5.QtCore import QObject, pyqtSlot
> from PyQt5.QtCore import QWinEventNotifier
> 
> 
> class MyController(QObject):
> 
>    def __init__(self, connect_to_decorated_slot=True) -> None:
>        super().__init__()
>        self.win_receive_event = int(win32event.CreateEvent(None, 0, 0, None))
>        self.qt_read_event_notifier = QWinEventNotifier(ctypes.c_int(self.win_receive_event), parent=self)
>        if connect_to_decorated_slot == True:
>            self.qt_read_event_notifier.activated.connect(self.decorated_event_slot)
>        else:
>            self.qt_read_event_notifier.activated.connect(self.event_slot)
> 
>    def event_slot(self, event):
>        print('Event')
> 
>    @pyqtSlot('Qt::HANDLE')
>    def decorated_event_slot(self, event):
>        print('Event')
> 
> 
> Running the code I get the following output(s):
> 
>>>> MyController(connect_to_decorated_slot=True)
> 
> Traceback (most recent call last):
>  File "<pyshell#0>", line 1, in <module>
>    MyController(connect_to_decorated_slot=True)
>  File "D:/test.py", line 14, in __init__
>    self.qt_read_event_notifier.activated.connect(self.decorated_event_slot)
> TypeError: connect() failed between activated(Qt::HANDLE) and decorated_event_slot()
> 
> 
>>>> MyController(connect_to_decorated_slot=False)
> 
> Traceback (most recent call last):
>  File "<pyshell#1>", line 1, in <module>
>    MyController(connect_to_decorated_slot=False)
>  File "D:/test.py", line 16, in __init__
>    self.qt_read_event_notifier.activated.connect(self.event_slot)
> TypeError: connect() failed between activated(Qt::HANDLE) and unislot()
> 
> 
> I guess I am completely missing something...

No, it's PyQt not handling a Qt weirdness properly. The actual type is 'HANDLE' but this is a type that is private to QWinEventNotifier.

Unfortunately I don't think there is a workaround until I fix it properly.

Phil


More information about the PyQt mailing list