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

redstone-cold redstone-cold at 163.com
Sun Apr 5 04:17:18 BST 2015


sorry ,I posted the wrong code last time, this is the right code 
https://bpaste.net/show/a8a5c72f9c0c
for slotFinished() if decorated with @pyqtSlot() in PyQt5 seems works fine ,but if not ,


Traceback (most recent call last):
  File "E:\network.py", line 57, in slotFinished
    print(reply, reply.error())
AttributeError: 'QAction' object has no attribute 'error'


PyQt4 doesn't care if  slotFinished() decorated with @pyqtSlot() or not , while PyQt5 does ,anyone can explain why ?








在2015年04月04 22时14分, "Yuya Nishihara"<yuya at tcha.org>写道:

On Sat, 4 Apr 2015 21:37:41 +0800 (CST), redstone-cold wrote:
> The PyQt4 version of the same code , self.sender() returns a QNetworkReply,
> the direct object that sent the signal,while in PyQt5,it  returns the
> original object that sent the signal.

I see no difference between PyQt4 and PyQt5. Both crashed because self.sender()
is a QAction in on_deleteTasks_triggered(), which is correct.

   Traceback (most recent call last):
     File "test.py", line 39, in on_deleteTasks_triggered
       reply.abort()
   AttributeError: 'QAction' object has no attribute 'abort'

> here, on_deleteTasks_triggered() call reply.abort(), thus emitted finished
> signal of reply, then slotFinished() was invoked, so I think the original
> object that sent the signal was QAction, the direct one should be
> QNetworkReply, QObject::sender() should return the DIRECT object that sent
> the signal in this case or else cause so many problems .

What happens if slotFinished() is decorated as @pyqtSlot() ?

> https://bpaste.net/show/9605c5d7e849
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150405/1ef5f475/attachment.html>


More information about the PyQt mailing list