[PyQt] QObject::​sender() returns the original object that sent the signal

Florian Bruhin me at the-compiler.org
Mon Apr 6 15:26:13 BST 2015


* Yuya Nishihara <yuya at tcha.org> [2015-04-06 21:55:52 +0900]:
> On Mon, 6 Apr 2015 15:35:08 +0800 (CST), redstone-cold wrote:
> > test code
> > https://bpaste.net/show/79b893f0d9fd
> > 
> > The PyQt4 version of the same code , self.sender() in downloadProgress,
> > no matter decorated with @pyqtSlot(int, int) or not, returns a QNetworkReply,
> > the direct object that sent the signal, when on_deleteTasks_triggered(),
> 
> Probably because reply.abort() doesn't emit finished() immediately on your
> PyQt4 environment. As I said before, I see the same issue on both PyQt4 and
> PyQt5.
> 
> The problem is that sender() returns the sender of the 1st signal
> 
> [...]

I usually use functools.partial[1] to pass the sender to the "real"
slot explicitely instead of using self.sender(). IMHO, that's cleaner
and less error-prone.

Florian

[1] https://docs.python.org/3/library/functools.html#functools.partial

-- 
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: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150406/fb17b071/attachment.sig>


More information about the PyQt mailing list