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

redstone-cold redstone-cold at 163.com
Tue Apr 7 13:26:39 BST 2015


Which changes should I make on the test code in order to use functools.partial[1] in it ?






在2015年04月06 22时26分, "Florian Bruhin"<me at the-compiler.org>写道:

* 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 --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150407/f07f42ff/attachment.html>


More information about the PyQt mailing list