File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -984,6 +984,14 @@ namespace fcn
984984 */
985985 virtual FocusHandler* _getFocusHandler ();
986986
987+ /* *
988+ * Detaches the given focus handler from every live widget.
989+ *
990+ * Call this before destroying a focus handler so widgets that
991+ * outlive it never dereference a dangling pointer.
992+ */
993+ static void _detachFocusHandlerFromAll (FocusHandler* focusHandler);
994+
987995 /* *
988996 * Adds an action listener to the widget. When an action event
989997 * is fired by the widget the action listeners of the widget
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ namespace fcn
101101 }
102102 mTop = nullptr ;
103103 }
104+ Widget::_detachFocusHandlerFromAll (mFocusHandler );
104105 Widget::_setVisibilityEventHandler (nullptr );
105106 Widget::_setGuiDeathListener (nullptr );
106107
Original file line number Diff line number Diff line change @@ -860,6 +860,15 @@ namespace fcn
860860 return mFocusHandler ;
861861 }
862862
863+ void Widget::_detachFocusHandlerFromAll (FocusHandler* focusHandler)
864+ {
865+ for (auto * widget : widgetInstancesRegistry ()) {
866+ if (widget != nullptr && widget->mFocusHandler == focusHandler) {
867+ widget->mFocusHandler = nullptr ;
868+ }
869+ }
870+ }
871+
863872 void Widget::_setVisibilityEventHandler (VisibilityEventHandler* visibilityEventHandler)
864873 {
865874 mVisibilityEventHandler = visibilityEventHandler;
You can’t perform that action at this time.
0 commit comments