Manually programmed GUI, guidata() not updating the handles struct
1 view (last 30 days)
Show older comments
The basic structure of my GUI is a figure with multiple tabs. Each tab is a panel with its own children buttons and other uicontrols. In one of the panels, i have a PushButton with a callback to a function that counts the amount of checkboxes selected on a different panel. My main handle structure is called 'TabHandles', where i store the overall figure object, each panel object, and other things. The pushbutton is coded as follows:
numberEventsButton = uicontrol('Parent',TabHandles(NumberOfTabs).TabPanel,'Style','PushButton',...
'String','# of Events Currently Selected (Push)','Callback',{@currentSelectionCounter});
The callback function is:
function currentSelectionCounter(~,~)
TabHandles = guidata(gcf);
totEvents = TabHandles(1).Counter;
TabHandles(2).Counter = 0;
for k=1:totEvents
newHandles(2).Counter = newHandles(2).Counter + get(newHandles(k).EventCheckbox,'Value');
end
guidata(gcf,TabHandles)
end
Using the debugger, the new local version of 'TabHandles' created in the callback function does indeed have the correct new value I'd like to pass to the main GUI handles sturct (which is TabHandles(2).Counter) , but after using guidata(gcf,TabHandles) the handles structure in the main GUI workspace does not update. I use guidata(gcf) to get the lastest copy of the TabHandles struct, and i then use guidata() with the 2 inputs to, in theory, save my new modified TabHandles back to the maimn figure. What am I doing wrong? Is there an issue with the PushButton being a child component of a panel, which is itself a child component of the figure? Been scratching my head for a while now
2 Comments
Accepted Answer
Rik
on 16 Aug 2022
The guidata struct is not a global variable. You should treat it as a mat file. When you write to it, other functions need to reload it to apply the changes.
So at any point where you expect changes to occur, make sure you reload the guidata struct.
0 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!