[PyQt] How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6
slepton at posteo.de
slepton at posteo.de
Tue Jan 31 11:59:51 GMT 2017
Hi Phil,
thanks for the quick reply.
1. Looking at QWinEventNotifier the Signal is voidptr, right?
class QWinEventNotifier(QObject):
"""
QWinEventNotifier(parent: QObject = None)
QWinEventNotifier(sip.voidptr, parent: QObject = None)
"""
def activated(self, sip_voidptr): # real signature unknown; restored
from __doc__
""" activated(self, sip.voidptr) [signal] """
pass
2. Looking at the connection error
TypeError: connect() failed between activated(Qt::HANDLE)
I would assume, that voidptr is acctually a Qt::HANDLE
(http://doc.qt.io/qt-5.6/qt.html#HANDLE-typedef) which I couldn't find
in from PyQt5.QtCore import Qt , is this even the right place to look?
3. I am not sure I understand correctly what to do, so far the slot I
connected to looked like
@pyqtSlot(int)
def event_slot(self, event):
# do something ...
For the @pyqtSlot decorator I additionally tried @pyqtSlot() and in a
desperate attempt @pyqtSlot(ctypes.c_int) since this would be the
correct type for the win32event.
What decorator can I use to further track down the problem?
Best regards
Sebastian
Am 31.01.2017 10:39 schrieb Phil Thompson:
> On 30 Jan 2017, at 11:19 pm, slepton at posteo.de wrote:
>>
>> Hello,
>>
>> I am trying to use QWinEventNotifier on PyQt 5.6 / Python 3.5 with a
>> custom slot. My Problem is, that I can't figure out what decorator to
>> use.
>>
>> The relevant code snippet looks like this:
>>
>>
>>
>> def register(self):
>> # Windows event
>> self.receive_event = win32event.CreateEvent(None, 0, 0, None)
>> # Code to register the event with the PCAN API
>> # ...
>> self.PCANrevieceEventHandler = QWinEventNotifier(parent=self)
>>
>> self.PCANrevieceEventHandler.setHandle(ctypes.c_int(self.receive_event))
>> self.PCANrevieceEventHandler.activated.connect(self.msg_recev)
>>
>>
>> @pyqtSlot( ) # I tried int, ctypes.c_int, ... nothing
>> def msg_recev(self, handle):
>> # read the buffer
>>
>>
>> I get TypeError: connect() failed between activated(Qt::HANDLE) and
>> unislot()
>>
>>
>> I know, that in Qt 5.8 there would be QtSerialBus to propperly handle
>> this, looking at the Qt src, QWinEventNotifier seems to be the right
>> thing to use...
>>
>> What is the propper way to do this?
>
> Try without a decorator and see what is actually passed in.
>
> Phil
More information about the PyQt
mailing list