GUI still executing code after it is closed
1 次查看(过去 30 天)
显示 更早的评论
I have a Matlab GUI and when a push button is pressed it performs a very long computation(hours long). If during this computation I decide I want to stop or doing something else I will press the close button(default top right corner). This will close the GUI(via an interrupt). However after the figure has closed the code continues to run, eating up system resources, and displaying graphs. When running matlab this hasn't been problem as I just use ctrl C to stop this as well. Now that I have compiled this and am about to redistribute this I need a way to completely stop the code without having the users do control alt delete.
I have tried various things in the CloseRequestFcn such as: 1) delete(handles.gui) 2) set(groot,'ShowHiddenHandles','on') c = get(groot,'Children'); delete(c) 3) delete(hObject); 4) close all force
None of which have worked.
0 个评论
回答(1 个)
Walter Roberson
2015-8-27
Graphics interrupts are not executed until the code calls figure() or pause() or drawnow() or uiwait() or waitfor()
You could have your code structured something like,
myfig = handle of your figure
user_quit = false;
for K = 1 : 324
for J = 1 : 3439324
drawnow();
if ~isgraphics(myfig);
%user closed the figure. React appropriately
user_quit = true;
break;
end
%now do a bite-sized amount of code, a couple of seconds or so
....
end
if user_quit; break; end
end
I used this structure as an example, to illustrate the point that "break" only breaks out of the innermost loop so you may need a check to break out of the outer loop
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!