Memory can not release correctly because of using lambda as slot
-
@JonB But without lambdas it can be hard e.g. to pass parameters. <== what do you mean? A slot can do the same things as in a lambda func, right?
-
@JonB But without lambdas it can be hard e.g. to pass parameters. <== what do you mean? A slot can do the same things as in a lambda func, right?
@JoeCFD said in Memory can not release correctly because of using lambda as slot:
what do you mean? A slot can do the same things as in a lambda func, right?
If types in signal and slot do not match you cant connect or pass directly... with lambda you can modify your received data and process it further.
-
@JoeCFD said in Memory can not release correctly because of using lambda as slot:
what do you mean? A slot can do the same things as in a lambda func, right?
If types in signal and slot do not match you cant connect or pass directly... with lambda you can modify your received data and process it further.
-
@Pl45m4 Slot is defined by yourself and you can match them without issues. Using lambda as slot may cause crash when the widget is destroyed. This happened in my app.
@JoeCFD said in Memory can not release correctly because of using lambda as slot:
Using lambda as slot may cause crash when the widget is destroyed. This happened in my app.
You might choose to raise your own topic for this, with example. Ooi, Python (PySide? PyQt?) or C++?
-
@JoeCFD said in Memory can not release correctly because of using lambda as slot:
Using lambda as slot may cause crash when the widget is destroyed. This happened in my app.
You might choose to raise your own topic for this, with example. Ooi, Python (PySide? PyQt?) or C++?
@JonB C++. For example, if the signal comes from another class outside a widget, the signal is connected to a lambda func in the widget. When the widget is destroyed, the lambda may still be attached to that signal. When the signal comes, the lambda tries to process the data of the widget. The app will crash now since the data of the widget does not exist anymore.
-
@JonB C++. For example, if the signal comes from another class outside a widget, the signal is connected to a lambda func in the widget. When the widget is destroyed, the lambda may still be attached to that signal. When the signal comes, the lambda tries to process the data of the widget. The app will crash now since the data of the widget does not exist anymore.
@JoeCFD
I'd be interested to see yourconnect()statement. If aQObjectis the slot object that should remove it as slot from all signals when destroyed, shouldn't it?MyWidget::MyWidget() { connect(externalObject, &ExternalSignal, this, [] () { }); }Doesn't that get disconnected during
~MyWidget()? -
@JoeCFD
I'd be interested to see yourconnect()statement. If aQObjectis the slot object that should remove it as slot from all signals when destroyed, shouldn't it?MyWidget::MyWidget() { connect(externalObject, &ExternalSignal, this, [] () { }); }Doesn't that get disconnected during
~MyWidget()?@JonB I did not do anything to disconnect in the destructor when lambda was used. I guess the disconnection was not done quickly enough while there are a lot of things going on in the code. Now I do disconnection manually even with slot in ~MyWidget() to avoid crash.
-
@JoeCFD
I'd be interested to see yourconnect()statement. If aQObjectis the slot object that should remove it as slot from all signals when destroyed, shouldn't it?MyWidget::MyWidget() { connect(externalObject, &ExternalSignal, this, [] () { }); }Doesn't that get disconnected during
~MyWidget()?@JonB said in Memory can not release correctly because of using lambda as slot:
@JoeCFD
I'd be interested to see yourconnect()statement. If aQObjectis the slot object that should remove it as slot from all signals when destroyed, shouldn't it?MyWidget::MyWidget() { connect(externalObject, &ExternalSignal, this, [] () { }); }Doesn't that get disconnected during
~MyWidget()?The problem is that neither PyQt nor PySide support using a context object. This removes two important properties for using lambda functions:
- The ability to specify which thread the slot should run in
- The ability to automatically disconnect when an indirect receiver is destroyed
-
@JonB said in Memory can not release correctly because of using lambda as slot:
@JoeCFD
I'd be interested to see yourconnect()statement. If aQObjectis the slot object that should remove it as slot from all signals when destroyed, shouldn't it?MyWidget::MyWidget() { connect(externalObject, &ExternalSignal, this, [] () { }); }Doesn't that get disconnected during
~MyWidget()?The problem is that neither PyQt nor PySide support using a context object. This removes two important properties for using lambda functions:
- The ability to specify which thread the slot should run in
- The ability to automatically disconnect when an indirect receiver is destroyed
@jeremy_k said in Memory can not release correctly because of using lambda as slot:
The problem is that neither PyQt nor PySide support using a context object. This removes two important properties for using lambda functions:
I asked whether @JoeCFD was talking about Python or C++ and he said C++.
-
@jeremy_k said in Memory can not release correctly because of using lambda as slot:
The problem is that neither PyQt nor PySide support using a context object. This removes two important properties for using lambda functions:
I asked whether @JoeCFD was talking about Python or C++ and he said C++.
@JonB said in Memory can not release correctly because of using lambda as slot:
@jeremy_k said in Memory can not release correctly because of using lambda as slot:
The problem is that neither PyQt nor PySide support using a context object. This removes two important properties for using lambda functions:
I asked whether @JoeCFD was talking about Python or C++ and he said C++.
That's clear. I was being expedient in responding to one of your previous comments.
@JonB said in Memory can not release correctly because of using lambda as slot:
@JoeCFD
But without lambdas it can be hard e.g. to pass parameters. -
@JoeCFD
But without lambdas it can be hard e.g. to pass parameters.@feiyuhuahuo
I said I think this is expected behaviour from Python, if it's a problem for you you need to work around if it's a deal-breaker.
Does executingself.action_bilinear.triggered.disconnect()recover the memory? That would disconnect all slots, hopefully including lambdas?@JonB
I add thisself.action_bilinear.triggered.disconnect()in closeEvent, but just doesn't work.