GUI inside another GUI
Afficher commentaires plus anciens
Hi everyone,
I want to open a GUI (GUI_Retrait) in my first GUI (GUI3) but I have trouble with it. I use GUIDE for GUI3 and I create GUI_Retrait without GUIDE.
To call GUI_Retrait I use the method described here : http://fr.mathworks.com/matlabcentral/answers/248830#answer_196171
I have an error in my first GUI when I'm calling the second one. The error is :
Error using getappdata
Value must be a handle.
Error in GUI3>Retrait_Callback (line 279)
handles.GUI_Retrait_struct=getappdata(handles.GUI_Retrait); % save the handle of
gui_b in gui_a
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GUI3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)GUI3('Retrait_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I think I don't create my second GUI (GUI_retrait) the right way. I don't know how to create the handle of the GUI itself.
Does someone know how to fix this?
Here is the code of my second GUI : (I have several checkboxes which depend on a number given by GUI3)
function handles=GUI_Retrait
%Retrive Datas from GUI3
handles.GUI3=getappdata(0,'GUI3'); % retrieve handle of GUI_A
handles.GUI3_struct=getappdata(handles.GUI3); % retrieve handle to the structure used in GUI_A
handles.GUI3_data=handles.GUI3_struct.UsedByGUIData_m; % retrieve data inside the structure
%Figure
handles.GUI_Retrait.h=figure('Name','Eprouvette(s) à retirer','NumberTitle','off','Position',[300 300 300 400]);
%PushButton
handles.GUI_Retrait.pb=uicontrol('Parent',handles.GUI_Retrait.h,'Style', 'Pushbutton',...
'String', {'Retirer'},...
'Position', [150 100 120 50],...
'Callback',@pb_Callback);
%Checkboxes
for i=1:handles.GUI3_data.n
str=sprintf('Eprouvette n°%s',num2str(i));
handles.GUI_Retrait.box(i)=uicontrol('Parent',handles.GUI_Retrait.h,...
'Style', 'checkbox',...
'String', {str},...
'Position', [20 400-50*i 100 50]);
end
guidata(handles.GUI_Retrait.h,handles);
Thanks. Clément
2 commentaires
Adam
le 30 Mar 2016
getappdata(handles.GUI_Retrait)
assumes that handles.GUI_Retrait is a graphics object that you have previously used setappdata to set some data on.
It is difficult to assess from the code you have posted because it doesn't seem to include the line that yields the error, but assuming your 'handles' here is the same one as that returned by your GUI_Retrait function then
handles.GUI_Retrait
is a structure, not a graphics object handle because you are just creating it with fields in a line such as:
handles.GUI_Retrait.h=figure('Name','Eprouvette(s) à retirer','NumberTitle','off','Position',[300 300 300 400]);
I'm not too familiar with doing a programmatic UI in a function because I always do mine in a class which naturally stores all the components I need so it doesn't require the concept of appdata so it's hard to give any concrete advice on small changes to fix your problem, especially since I suspect some of the problems originate from code you haven't included.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!