GUI callbacks now broken

5 Ansichten (letzte 30 Tage)
tlawren
tlawren am 29 Jun. 2012
I've been making some changes to a GUI and I broke a lot of my callbacks in the process. Specifically, the callbacks that are now broken are all saved in separate m-files outside of my main GUI file. The only changes I made were to the names of the callback functions themselves. I changed the names in the function signatures in GUIDE (inside Property Inspector) and I changed the names in the associated m-files and now none of the changed callbacks work. To be sure, nothing happens when I press any of the buttons associated these callbacks. Moreover, if I hit the buttons multiple times, a second instance of my GUI is loaded indicating that the opening function was executed again.
Do I need to change something else? All of the callbacks worked fine in separate files to begin with, but now they don't.
I should also note that if I copy and paste the callbacks back into the main GUI file, then the callbacks work again.
EDIT 1:
If I press one of the buttons with a broken callback a few times then I get the following error.
Error using handle.handle/get
Invalid or deleted object.
Error in movegui>getActivePositionProperty (line 235)
actPosProp = get(fig,'ActivePositionProperty');
Error in movegui (line 115)
oldposmode = getActivePositionProperty(fig);
Error in openfig (line 109)
movegui(fig(n), 'onscreen');
Error in gui_mainfcn>local_openfig (line 286)
gui_hFigure = openfig(name, singleton, visible);
Error in gui_mainfcn (line 234)
gui_hFigure = local_openfig(gui_State.gui_Name, 'reuse',gui_Visible);
Error in main_gui (line 23)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)main_gui('ConnectSystem',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
The movegui error is kind of odd.
  3 Kommentare
tlawren
tlawren am 29 Jun. 2012
No, it is not on my MATLAB path and all the files are in the same directory too. I'm not using cd() in the code, but I do load plenty of data files during startup. If cd() can get called during a load, then that might be my problem. I will have to check. Thanks for the reply!
Walter Roberson
Walter Roberson am 29 Jun. 2012
load() itself will not change directories.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 30 Jun. 2012
I really recommend you don't alter the callback names that GUIDE picks. If you want custom names, just call that custom-named function from within the callback. For example in the callback for btnSelectFolder, let it use the name btnSelectFolder_Callback which it wants to, then inside that function call your function, like this:
function btnSelectFolder_Callback(hObject, eventdata, handles)
% hObject handle to btnSelectFolder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fprintf(1, 'Entered btnSelectFolder_Callback');
% Now call your function with your special name.
usersFolder = MyCustomFolderSelectionFunction();
fprintf(1, 'Leaving btnSelectFolder_Callback');
return;
Fortunately, you can fix whatever you messed up. In the property inspector for your control (e.g. your button), there is a property called Callback. Click in there and delete everything, then click the little icon to the left and it will fix it by putting in the automatic, default name like it started out with before you mucked it up.
If you're having your callbacks, the same ones in the callback property of GUIDE, be in separate m-files, then I doubt that will work, just like you're observing. How would it know to call those? It's going to look only in the m-file associated with your fig file, not all over the search path. And if it doesn't find it there, it will complain. That's why I said to use the original names and simply call your other m-file from within the callback, as I demonstrated above.
  3 Kommentare
tlawren
tlawren am 2 Jul. 2012
Bearbeitet: tlawren am 2 Jul. 2012
All of my broken callbacks use to work fine, and they are all saved in separate m-files. Specifically, the changes that I made were to remove the "_Callback" tag from the function and file names. I made the changes in GUIDE, in the function declarations in the m-file, and to the m-file filenames.
If, I copy and paste my callbacks back into the main m-file for my gui, then my callbacks work again.
Walter Roberson
Walter Roberson am 2 Jul. 2012
Time to use the debugger and check the Callback properties

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by