[PyKDE] Lambda function call in connect statement

Phil Thompson phil at river-bank.demon.co.uk
Thu Mar 1 20:42:49 GMT 2001


"Aaron J. Ginn" wrote:
> 
> I'm trying to call a function using a lambda call with PyQt.  I bound
> the function call to a button using the following commands:
> 
> --------------------------------------------------------------------
>         self.top_struct_button = QPushButton('Change Top
> Structure',self.top_struct_hb)
> 
>         self.connect( self.top_struct_button, SIGNAL( "clicked()" ),
>                       lambda s=self,o=ver_obj: s.changeTopStruct(o))
> --------------------------------------------------------------------
> 
> For debug purposes, changeTopStruct is an empty function:
> 
> --------------------------------------------------------------------
>     def changeTopStruct(self, drc_obj):
>         """
>         Pops up an input dialog to prompt user for new top structure
> name.
>         """
> --------------------------------------------------------------------
> 
> Whenever I press the button, I get a segfault.  Now the function is not
> doing anything, so the segfault must be occurring because of the lambda
> statement.
> 
> Are lambda statements that call a function supported in PyQt?  I have to
> use a lambda because I need to suppress the execution of the function
> until I press the button, and I have to pass an argument to the
> function.
> 
> Am I using lambda improperly here?  Is there some special syntax I need
> to use in the connect statement to use lambda?

As lambda functions are supposed to be "syntactic sugar for a normal
function definition" I don't see how using it helps you. Your function
wouldn't be executed until the button click anyway.

However, I don't like segfaults - send me a small but complete script
that demonstrates the problem and I'll take a look.

Phil




More information about the PyQt mailing list