[PyKDE] Is QObject.sender() working ?
Yves BAILLY
kafka.fr at netcourrier.com
Sat May 19 08:23:22 BST 2001
Hello,
Thanks for your answer.
On Friday 18 May 2001 23:59, Greg Green wrote:
> Looking at the Qt documentation:
>
> --------------------------------------------------------------------
> [...]
> signals are connected to a single slot. The sender is undefined if
> the slot is called as a normal C++ function.
> ---------------------------------------------------------------------
>
> I suspect the last sentence is the problem. Looking at the PyQt code
> shows the sender function getting called after some other things. I
> would just hook each button up to a separate slot, ugly, but it will
> work.
But I took care of calling sender() as soon as I enter in the slot,
to store its value in a variable before printing it.
And it *works* in C++, so why not here ?
Now, each button to a different slot is not the solution here : this
is an example program, the real program contains a dynamically-build
form: so I've no idea of the real number of buttons (it may vary between
about 10, to more than 50...)
So, how to do in those cases ?
> > # 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()
Sorry, this was mistyped :
> > print "-- Button clicked:", obj()
> > [...]
> > -- Button clicked: None
> > -- Button clicked: None
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