Effacer les filtres
Effacer les filtres

Class GUI app CloseRequestFcn missing figure handles

3 vues (au cours des 30 derniers jours)
Orangelynx
Orangelynx le 8 Avr 2018
Modifié(e) : Orangelynx le 8 Avr 2018
Consider this simple example:
classdef multi_gui
properties
fig1
fig2
end
methods
function obj = multi_gui()
obj.fig1 = figure('CloseRequestFcn', @obj.closeApp);
obj.fig2 = figure('CloseRequestFcn', @obj.closeApp);
end
function closeApp(obj, hObject, eventdata)
delete(obj.fig1)
delete(obj.fig2)
end
end
end
It's an app with 2 figures and when one is closed, the other is supposed to be closed as well. However, something is seriously going wrong in the CloseReqeustFcn callback. Using the debugger, I can see that fig1 and fig2 in obj in the callback are "unset", and therefore cannot be closed. What's going on here?

Réponse acceptée

Orangelynx
Orangelynx le 8 Avr 2018
Modifié(e) : Orangelynx le 8 Avr 2018
Solved it myself eventually.. apparently, the state of the "obj" is saved at the point when the callback is set, so when setting the callback of fig2, fig2 is not yet set in obj. similarly, when setting the callback of fig1, neither fig1 or fig2 exist in obj yet. so the solution looks like this.
function obj = multi_gui()
obj.fig1 = figure();
obj.fig2 = figure();
obj.fig1.CloseRequestFcn = @obj.closeApp;
obj.fig2.CloseRequestFcn = @obj.closeApp;
end
PS: more detailed explanation of the problem and "cleaner" ways of solving this are welcome.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by