GUI callbacks now broken
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2012-6-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!