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

Yuya Nishihara yuya at tcha.org
Sat Apr 4 12:55:16 BST 2015


On Sat, 4 Apr 2015 13:27:50 +0200, Florian Bruhin wrote:
> * redstone-cold <redstone-cold at 163.com> [2015-04-04 19:08:05 +0800]:
> > https://bpaste.net/show/9605c5d7e849
> > when self.deleteTasks triggered, self.sender() should return QNetworkReply rather than QAction
> > 
> > 
> > if the url doesn't work there, please use another URL without redirection and also  direct to some large file.
> 
> I don't understand - how would the self.deleteTasks QAction possibly
> know anything about the QNetworkReply? It's an object ompletely
> independent from the reply. And deleteTasks.triggered gets sent by the
> QAction, so why would self.sender() suddenly be a QNetworkReply?

FWIW, if on_deleteTasks_triggered() can call reply.abort(), self.sender() would
return a QAction in slotFinished(). I think it should be a QNetworkReply.

    # NOT DECORATED as @pyqtSlot()
    def slotFinished(self):
        reply = self.sender()
        # reply is a QAction if not decorated as @pyqtSlot(), but
        # a QNetworkReply if decorated
        print(reply, reply.error())

    # DECORATED
    @pyqtSlot()
    def on_deleteTasks_triggered(self):
        #reply = self.sender()
        reply = self.reply
        reply.abort()

IIRC, there's a bug that sender() returns wrong object if the slot is invoked
in the decorated slot of the same object.

Using PyQt5 5.3.2+dfsg-3 on Debian sid.

Regards,


More information about the PyQt mailing list