
Separate Callback Functions in AppDesigner
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Cris LaPierre
el 27 de Abr. de 2025
Editada: Cris LaPierre
el 27 de Abr. de 2025
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.
Respuestas (1)
Image Analyst
el 26 de Abr. de 2025
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 comentario
Ver también
Categorías
Más información sobre Maintain or Transition figure-Based Apps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
