
Separate Callback Functions in AppDesigner
31 views (last 30 days)
Show older comments
Having defined a callback function for an application "Quit" button, it was also assigned to be the CloseRequestFunction callback. I've now determined I really need to separate those to avoid potential issues if the user were to try to close the app while processing.
However, AppDesigner only renames the one existing callback function; it will not allow me to now create a new callback for either action and since the callbacks are in the protected section, one can't add a new function manually.
How can one disassociate the CloseRequestFunction and QuitButton callbacks from the one present function to have two independent callbacks?
ADDENDUM
There is a workaround; one can parse the passed event stuct and determine which object is the instigator and thus branch inside the one callback function.
But, unless there is some other way to edit the app file short of deleting and recreating controls, it seems to be a hole in the AppDesigner user interface.
4 Comments
Cris LaPierre
on 27 Apr 2025 at 1:07
Edited: Cris LaPierre
on 27 Apr 2025 at 2:09
I suppose maybe the way out would be to select <no callback> for one and then it would let me create a new one?
Yes, that is what I would do.
You could also create the function in the app first. It would then appear in the dropdown list, where you could select it as the callback for that control.
Answers (1)
Image Analyst
on 26 Apr 2025 at 18:20
The callback for a button, and the CloseRequestFunction callback for the figure are two entirely separate functions. For the Quit button you should see a function like
function QuitButtonPushed(app, event)
% Quit without asking user for confirmation.
delete(app);
end
For the close request function you should see something like
% Close request function: UIFigure
function CloseRequestFcn(app, event)
% Ask user if they really want to exit the program.
promptMessage = sprintf('Do you want to quit this program?');
titleBarCaption = 'Quit?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Yes - Quit', 'No - Continue', 'No - Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
delete(app) % Shut down program
end
% Else you get here and the program will continue.
end
I have no idea why they are the same function for you. Can you attach your .mlapp file?
1 Comment
See Also
Categories
Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!