[PyQt] Decorated slot has no compatible signature

Florian Bruhin me at the-compiler.org
Mon Nov 21 14:33:40 GMT 2016


* Tony Arnold <tony.arnold at manchester.ac.uk> [2016-11-21 13:42:11 +0000]:
> On Sun, 2016-11-20 at 22:46 +0000, Tony Arnold wrote:
> > Florian,
> > 
> > On Sun, 2016-11-20 at 21:19 +0100, Florian Bruhin wrote:
> > > * Tony Arnold <tony.arnold at manchester.ac.uk> [2016-11-20 19:16:01
> > > +0000]:
> > > > I'm using QNetworkManager to upload some files to a site. To see
> > > > the
> > > > progress I've defined a slot that gets connected to the
> > > > uploadProgress
> > > > signal.
> > > > 
> > > > The slot is defined:
> > > > 
> > > >     @pyqtSlot(int, int)
> > > >     def updateDataTransferProgress(self, readBytes, totalBytes):
> > > > 
> > > > and is connected to a reply object thus:
> > > > 
> > > >   reply.uploadProgress.connect(self.updateDataTransferProgress)
> > > > 
> > > > However, this gives the error message:
> > > > 
> > > > TypeError
> > > > "decorated slot has no signature compatible with
> > > > uploadProgress(qint64,qint64)"
> > > > 
> > > > I'm running on Ubuntu 16.10 which has PyQt5.7. I believe slot
> > > > verification has been tightened
> > > > up in this version, but as far as I can see the above declaration
> > > > is correct.
> > > > 
> > > > How can I fix this?
> > > 
> > > Use @pyqtSlot('qint64', 'qint64') instead.
> > 
> > Thanks. I tried this and I now get
> > 
> >     The debugged program raised the exception unhandled TypeError
> >     "connect() failed between uploadProgress(qint64,qint64) and
> >     updateDataTransferProgress()"
> 
> A bit more experimenting. I took Florian's code from https://riverbankc
> omputing.com/pipermail/pyqt/2016-April/037370.html and modified it to
> put the slot inside a class. And it failed. It also fails changing the
> decoration to use 'qint64'. It fails with:
> 
> QObject::connect: Cannot connect
> QNetworkReplyHttpImpl::downloadProgress(qint64,qint64) to
> (null)::slot(qint64,qint64)
> Traceback (most recent call last):
>   File "slot_example.py", line 16, in <module>
>     reply.downloadProgress.connect(obj.slot)
> TypeError: connect() failed between downloadProgress(qint64,qint64) and
> slot()
> 
> 
> Here is the version of the code:
> 
> from PyQt5.QtWidgets import QApplication
> from PyQt5.QtCore import pyqtSlot, QUrl
> from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
> 
> class test():
>     @pyqtSlot('qint64', 'qint64')
>     def slot(self, num1, num2):
>         pass
> 
> a = QApplication([])
> 
> obj=test()
> 
> nam = QNetworkAccessManager()
> reply = nam.get(QNetworkRequest(QUrl('http://www.riverbankcomputing.com
> /')))
> reply.downloadProgress.connect(obj.slot)
> 
> a.exec_()
> 
> Can others get this to work, or could this be to do with my system? Ím
> running on Ubuntu 16.10.

If your class isn't a QObject, @pyqtSlot won't work (as it registers
the method as a "real" slot with Qt).

If you want to connect to a normal function, or a method of a
non-QObject, then don't use @pyqtSlot (like Detlev suggested).

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161121/b43d3300/attachment.sig>


More information about the PyQt mailing list