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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

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

slepton
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? 

Best regards

Sebastian

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 30 Jan 2017, at 11:19 pm, [hidden email] 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
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

slepton
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, [hidden email] 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
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 31 Jan 2017, at 11:59 am, [hidden email] wrote:

>
> 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?

@pyqtSlot('Qt::HANDLE')

should work, but you don't need a decorator at all.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

slepton
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...

Sebastian




Am 31.01.2017 13:14 schrieb Phil Thompson:

> On 31 Jan 2017, at 11:59 am, [hidden email] wrote:
>>
>> 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?
>
> @pyqtSlot('Qt::HANDLE')
>
> should work, but you don't need a decorator at all.
>
> Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 31 Jan 2017, at 12:39 pm, [hidden email] 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
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 31 Jan 2017, at 1:06 pm, Phil Thompson <[hidden email]> wrote:

>
> On 31 Jan 2017, at 12:39 pm, [hidden email] 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.

There is an untested fix in tonight's PyQt5 snapshot.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

dchou4u581
This post was updated on .
I am having exactly the same issue too. I downloaded Anaconda 5.1 which has
Python version 3.6. I am also getting the error: TypeError: connect() failed
between activated(Qt::HANDLE) and unislot(). When I ran the same code with
WinPython, it runs just fine.

Phil, you mentioned that you had put in a fix in PyQt? Starting which
version of PyQt was the fix placed in, and if there is a workaround, I would really appreciate some pointers.

Thanks a lot,
Dennis



--
Sent from: http://python.6.x6.nabble.com/PyQt-f1792048.html
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 10 Mar 2018, at 1:50 am, dchou4u581 <[hidden email]> wrote:
>
> I am having exactly the same issue too. I downloaded Anaconda 5.1 which has
> Python version 3.6. I am also getting the error: TypeError: connect() failed
> between activated(Qt::HANDLE) and unislot(). When I ran the same code with
> WinPython, it runs just fine.
>
> Phil, you mentioned that you had put in a fix in PyQt? Starting which
> version of PyQt was the fix placed in?

Can you point me to the email that I said that?

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 11 Mar 2018, at 9:23 pm, Dennis C <[hidden email]> wrote:
>
> Hi Phil, it is in the thread http://python.6.x6.nabble.com/How-to-connect-the-activated-signal-of-QWinEventNotifier-to-a-custom-slot-in-pyqt-5-6-td5208531.html#a5230276
>
> You mentioned in a post there was going to be an untested fix.

The change was in PyQt v5.8.

Phil

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 12 Mar 2018, at 4:01 pm, Dennis Chou <[hidden email]> wrote:
>
> Thanks Phil.
>
> Looks like all the PyQt packages in Anaconda are older than v5.8. Could you point me to the patch files so that I can try to patch the changes into my installed version? Or where I may find v5.8 or later version on the Anaconda website.

This was the patch...

Phil


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

qwineventnotifier.sip.patch (578 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

dchou4u581
Strange, still the same connect problem. Do I need to reload the extension or
something after I modifed the file?

The file I changed is at Anaconda3\sip\PyQt5\QtCore\qwineventnotifier.sip.
This same file is also at
Anaconda3\pkgs\pyqt-5.6.0-py36hb5ed885_5\sip\PyQt5\QtCore.






--
Sent from: http://python.6.x6.nabble.com/PyQt-f1792048.html
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 12/03/2018 18:26, dchou4u581 wrote:
> Strange, still the same connect problem. Do I need to reload the
> extension or
> something after I modifed the file?
>
> The file I changed is at
> Anaconda3\sip\PyQt5\QtCore\qwineventnotifier.sip.
> This same file is also at
> Anaconda3\pkgs\pyqt-5.6.0-py36hb5ed885_5\sip\PyQt5\QtCore.

You have to re-build PyQt.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: How to connect the activated signal of QWinEventNotifier to a custom slot in pyqt 5.6

Phil Thompson-5
On 12 Mar 2018, at 8:32 pm, dchou4u581 <[hidden email]> wrote:
>
> Hi Phil, I am a Python newbie. Could you point me to some FAQ on how to build
> Anaconda PyQt5?

I know nothing about Anaconda.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt