[PyKDE] Is QObject.sender() working ?
Yves BAILLY
kafka.fr at netcourrier.com
Fri May 18 09:06:26 BST 2001
Hi all,
Sorry if this as already been reported.
Look at this little code :
class MyWidget(qt.QWidget):
def __init__ (self, *args):
apply (qt.QWidget.__init__, (self,)+args)
self.vbox = qt.QVBoxLayout(self)
# Create two buttons
self.bt1 = qt.QPushButton("Button 1", self) ;
self.bt2 = qt.QPushButton("Button 2", self) ;
# Print button references
print "Button 1:", self.bt1
print "Button 2:", self.bt2
# Add them in the layout
self.vbox.addWidget(self.bt1)
self.vbox.addWidget(self.bt2)
# Connect both buttons to the same slot
self.connect(self.bt1, qt.SIGNAL("clicked()"), self.Clicked)
self.connect(self.bt2, qt.SIGNAL("clicked()"), self.Clicked)
def Clicked(self):
obj = self.sender()
print "-- Button clicked:", self.sender()
And here's a sample output, where I clicked both buttons :
[yves at kafka ConfiMake]$ ./test.py
Button 1: <qt.QPushButton instance at 0x82eb92c>
Button 2: <qt.QPushButton instance at 0x82efbcc>
-- Button clicked: None
-- Button clicked: None
So : the QObject.sender() function seems to return always "None".
Then I did the very same program in C++ (pure Qt), clicking also on
both buttons, and this is the output :
[yves at kafka ConfiMake]$ ./test.x
Button 1: 0x8088120
Button 2: 0x8088358
-- Button clicked: 0x8088120
-- Button clicked: 0x8088358
This time, QObject::sender() works fine...
Is this a bug in PyQt ? If not, how can I find the sender of a signal ?
Please help.
Best regards,
--
.~. __________________________
/V\ Linux / \ ___
// \\ Power | Yves BAILLY | /" "\
/( )\ | kafka.fr at netcourrier.com | ( @ _ @ )
- ^^-^^ -------\__________________________/----oOO (_) OOo------
LUG Dijon : http://www.coagul.org
More information about the PyQt
mailing list