PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 344 - sender() returns None when use partial or lambda
: sender() returns None when use partial or lambda
Product: PySide
Classification: Unclassified
Component: PySide
: 0.4.0
: PC MS Windows XP/Vista/7
: P3 normal
Assigned To: renato filho
  Show dependency treegraph
Reported: 2010-09-06 03:25 EEST by kim.dohhyoung
Modified: 2010-10-13 13:53 EEST (History)
8 users (show)

See Also:

test sender() wrapped by partial or lambda (778 bytes, application/python)
2010-09-06 03:25 EEST, kim.dohhyoung

Note You need to log in before you can comment on or make changes to this bug.
Description kim.dohhyoung 2010-09-06 03:25:53 EEST
Created attachment 80 [details]
test sender() wrapped by partial or lambda

When I used the sender() method under PyQt4, it returned the sender object even
if it was wrapped by partial or lambda.
However, when I used the same code under PySide, it returned None.

See the attached code for details.
Comment 1 renato filho 2010-09-14 15:01:24 EEST
I have checked your test case and: This is a correct behavior. If you are using
a lambda as slot you can not have the sender object because PySide does not
know for which QObject set the sender.

The PyQt has this behavior due the way they implement the sender function and
this generates some mistakes like: any object that you call ".sender()"
function will return the same object. 
E.g: if you create a new QObject inside your "on_signal" function and call the
"sender" function from this object it will return the same object as returned
by self.sender()

Example code:

class MyObject(QObject):
    def on_signal(self):
        o = QObject()
        sender = self.sender()
        print sender
        print o.sender() // this return the same object as self.sender()

this is completely wrong and PySide avoids this kind of error.

Then if you want use the sender function, connect your signal with some other
QObject like these examples below:

a.connect(a, SIGNAL("s2()"), b.on_signal)
a.connect(a, SIGNAL("s2()"), b, SLOG("on_signal()")

I will mark the bug as invalid as this is taken as correct behavior.
If you have more questions, please reopen the bug then we can discuss more
about that.