Using lambda expression to connect slots in pyqt

前端 未结 3 1190
清酒与你
清酒与你 2020-11-22 12:06

I am trying to connect slots with lambda functions, but it\'s not working the way I expect. In the code below, I succeed in connecting the first two buttons correctly. For t

3条回答
  •  时光取名叫无心
    2020-11-22 13:09

    Beware! As soon as you connect your signal to a lambda slot with a reference to self, your widget will not be garbage-collected! That's because lambda creates a closure with yet another uncollectable reference to the widget.

    Thus, self.someUIwidget.someSignal.connect(lambda p: self.someMethod(p)) is very evil :)

提交回复
热议问题