GUI stops working after pushbutton function has completed

3 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Meade
Meade il 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 Commenti
Meade
Meade il 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 il 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.

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by