[PyKDE] Lambda function call in connect statement

Aaron J. Ginn aaron.ginn at motorola.com
Mon Mar 5 17:09:53 GMT 2001

Phil Thompson wrote:
> Sorry - I should have noticed this right at the start...
> The problem is that you are not keeping a reference to the function
> object that lambda returns - so it is getting garbage collected
> immediately. The signal is them emitted to an object that no longer
> exists, hence the segfault. Change the code to be something like...
>         self.lam = lambda s=self,x=num:s.changeTopStruct(x)
>         self.connect( self.top_struct_button, SIGNAL( "clicked()" ),
>                       self.lam )
> QObject.connect does not keep a reference to the slot object to avoid
> (potential) hidden circurlar references - but it does mean that you have
> to manage them yourself.
> The weakreferences module in Python 2.1 looks interesting - it might
> offer a more programmer friendly solution.
> Phil

Great!  This works.  I had a feeling the problem was that I was using
lambda incorrectly.

Aaron J. Ginn                    Phone: 480-814-4463
Motorola SemiCustom Solutions    Pager: 877-586-2318
1300 N. Alma School Rd.          Fax  : 480-814-4463
Chandler, AZ 85226 M/D CH260     mailto:aaron.ginn at motorola.com

More information about the PyQt mailing list