fix: Do not use lambda in QMenuItemAction.destroyed callback#183
fix: Do not use lambda in QMenuItemAction.destroyed callback#183tlambert03 merged 10 commits intopyapp-kit:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 31 31
Lines 1786 1785 -1
=========================================
- Hits 1786 1785 -1 ☔ View full report in Codecov by Sentry. |
|
I do not understand this test fail |
|
Thanks for the fix @Czaki. that test fail was definitely a weird one. Ultimately, I was able to track it down to this line action = QMenuItemAction(item, app=app, parent=menu)and a few other things:
So, simply changing you'll note I made a bunch of other changes to the caching pattern in 1fb13fb. While trying to debug, I got rid of |
|
i'll leave this here for the day in case you want to have another look, and then will merge this evening |
| actions = menu.actions() | ||
| for action in actions: | ||
| menu.removeAction(action) |
There was a problem hiding this comment.
interesting. are both of these required to be able to use create(parent=...) here? (i.e. not using clear as well as using setParent() inside of create?)
happy to go with whatever works best. just curious
There was a problem hiding this comment.
We need to keep reference to actions to prevent them being garbage collected, but we need to remove them from the menu before rebuild.
|
thanks! |
|
Could I request for bug fix release after merge this? |
|
absolutely. i prefer to keep releases as close to main as possible and avoid lengthy delays :) |
|
Just a question, I did not follow:
The first part makes sense but I do not understand the 2nd part. What does "qt will not try to trigger the method of destroyed objects" cause in this context ? Thanks |
Qt (And same for psygnal), when you connect a method to a signal, before calling callback, try first to validate if the object is still alive. And if it is already deleted then callback is not triggered. When lamda is used, then there is no option to easy check if all referred objects still exist. |
In napari tests I got segfaults, after local debugs it points to lambda that are modified in this PR.
In general, using the method is safer, as qt will not try to trigger the method of destroyed objects.