フィルターのクリア

Class GUI app CloseRequestFcn missing figure handles

3 ビュー (過去 30 日間)
Orangelynx
Orangelynx 2018 年 4 月 8 日
編集済み: Orangelynx 2018 年 4 月 8 日
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?

採用された回答

Orangelynx
Orangelynx 2018 年 4 月 8 日
編集済み: Orangelynx 2018 年 4 月 8 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by