GUI stops working after pushbutton function has completed

3 Ansichten (letzte 30 Tage)
Oscar Knights
Oscar Knights am 20 Apr. 2016
Kommentiert: Oscar Knights am 22 Apr. 2016
I have created a GUI (called GNgui) using GUIDE that runs a function when a 'Scan' button is pressed. It disables all the other buttons/fields in the GUI until it stops running, where it enables all the buttons again.
After the function runs (successfully), I'd like to be able to hit the 'Scan' button again to repeat the process, but every time I do, I get the following error message:
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('fileName_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
This isn't mutually exclusive to that push button either. When I try to press any other button (or even try to close the GUI window), I get a very similar error.
Any ideas? I've attached my .m file.
PS: I realise the code is a little messy, I'm trying to update and improve on some code someone else wrote.
  2 Kommentare
Image Analyst
Image Analyst am 20 Apr. 2016
We'd need the .fig file also.
Oscar Knights
Oscar Knights am 20 Apr. 2016
Apologies... I've attached the .fig file.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Meade
Meade am 20 Apr. 2016
I believe that the call back is written incorrectly. Your anonymous function syntax is telling the callback function that the second input is "evt" which is a struct by default. However, you're passing "hObj" as the second input.
try this:
@(hObject,eventdata)GNgui(hObject,eventdata,guidata(hObject))
  7 Kommentare
Meade
Meade am 21 Apr. 2016
Ok, so the problem seems to be that the 'handles' argument that is being passed to ALL your callbacks is empty.
I can't run the full gui since it's looking for some sort of COM connection, but you need to get all the handles for all the things you created in the GUIDE creator.
As a start, swap lines 41:45 with these
hFig = ancestor(hObject,'figure');
handles = guihandles(hFig);
% Choose default command line output for GNgui
handles.output = hObject;
% Update handles structure
guidata(hFig, handles);
This adds the structure 'handles' as guidata to the figure. Then, whenever a callback has the 'handles' arument, it should get this list of items.
Oscar Knights
Oscar Knights am 22 Apr. 2016
I updated lines 41:45 with the code you provided but I still receive the following error:
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('fileName_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('scanButton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
When you say I need to 'get all the handles', what should I do with them? Again, sorry about being a bit of a novice when it comes to these things.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by