GUI stops working after pushbutton function has completed
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 20 de Abr. de 2016
We'd need the .fig file also.
Oscar Knights
el 20 de Abr. de 2016
Respuestas (1)
Meade
el 20 de Abr. de 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 comentarios
Oscar Knights
el 21 de Abr. de 2016
Meade
el 21 de Abr. de 2016
Remove 'fileName_Callback' and then put your debug stop inside the callback function (the little red dot to the left of the line).
What does it report?
Oscar Knights
el 21 de Abr. de 2016
Meade
el 21 de Abr. de 2016
Can you post the code for your 'scan button'?
Oscar Knights
el 21 de Abr. de 2016
Meade
el 21 de Abr. de 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
el 22 de Abr. de 2016
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!