필터 지우기
필터 지우기

Terminating script after closing GUI window.

조회 수: 6 (최근 30일)
Mark
Mark 2015년 4월 5일
답변: Walter Roberson 2016년 1월 15일
Hi,
my problem is that when Im trying to close my GUI window through the close request function, the script is still going and it spits out an error, because the object it's trying to access is already deleted.
Is there a way to terminate the script in the closing function? In the main program you can do return; pretty easily but here I'm unsure.
I'm using delete(hObject) / delete(handles.figure1)
Could you please help me?
Thank you.
:)
  댓글 수: 3
Mark
Mark 2015년 4월 8일
The code in the close request function is just clc; to clear text from command window and delete(handles.figure1); to close my GUI window. I searched online and didn't really come across a code to completely stop running of the script in midst of waiting for input.
It is fine if the code hasn't started or when it's finished, but I'm implementing several 'stops' where the program waits (waitfor function) until the button 'Next' is pressed and when I try to quit the program then, it's apparent from the error that the code just continues but I've already deleted the figure and all objects in it and it's trying to access it now unsuccessfuly so it crashes.
So i'm need of something to stop the code not just delete the objects.. Something like 'return' but in function.
Error using matlab.ui.control.UIControl/set
Invalid or deleted object.
Error in GUIThesis>waitNext (line 634)
set(h.btnNext,'Value',0);
Error in GUIThesis>btnStart_Callback (line 168)
waitNext()
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUIThesis (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUIThesis('btnStart_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating DestroyedObject Callback
>>
Ali
Ali 2016년 1월 14일
I have the same problem. Did you find out how to fix it Mark?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 15일
No, callbacks have no direct way of instructing running functions to do anything. Running functions need to query whether they have been asked to do something. For example they could ask whether their figure handle is still valid.
If you are using R2014b or later you can use isgraphics() to determine whether something is a valid graphics handle. If you are using an earlier MATLAB then use ishandle()

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by