Borrar filtros
Borrar filtros

Sending values from a DialogApp to MainApp, Appdesigner

5 visualizaciones (últimos 30 días)
Furkan Karaman
Furkan Karaman el 3 de Oct. de 2023
Respondida: Amish el 30 de Oct. de 2023
I try to send values from a DialogApp to a Mainapp. The following example worked for a while but now it doesn't . Can anyone tell me where my mistake is?
dialogApp:
properties (Access = private)
CallingApp % Description
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, mainapp, uT, lT, uH, lH)
app.CallingApp = mainapp;
app.uppertresholdEditField.Value = uT;
app.lowertresholdEditField.Value=lT;
app.upperhysteresisthresholdEditField.Value=uH;
app.lowerhysteresisthresholdEditField.Value=lH;
end
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
get_adv_edg_data(app.CallingApp,app.uppertresholdEditField.Value,app.lowertresholdEditField.Value,app.upperhysteresisthresholdEditField.Value,app.lowerhysteresisthresholdEditField.Value);
delete(app)
% Close request function: UIFigure
function AdvEdg_Closerequest(app, event)
% Delete the dialog box
delete(app)
end
end
MainApp
properties (Access = private)
DialogApp
upT=0;
loT=0;
upH=0;
loH=0;
end
methods (Access = public)
function get_adv_edg_data(app,uT, lT, uH, lH)
app.upT=uT;
app.loT=lT;
app.upH=uH;
app.loH=lH;
end
end
methods (Access = private)
function startupFcn(app)
get_adv_edg_data(app,app.upT,app.loT,app.upH,app.loH);
end
%functions follow which should the values
end
  2 comentarios
Harald
Harald el 4 de Oct. de 2023
Hi,
in what way does it not work anymore? If you are getting an error message, please post it.
Please consider attaching the .mlapp files to make it easier to reproduce the problem.
Best wishes,
Harald
Mohammad Sami
Mohammad Sami el 4 de Oct. de 2023
I dont see where do you call the dialog app in your main app.

Iniciar sesión para comentar.

Respuestas (1)

Amish
Amish el 30 de Oct. de 2023
Hi Furkan,
The code you provided seems to be an attempt to pass values from a dialog app to a main app in MATLAB App Designer. There are some issues with the code that has been posted along with your question, but it is difficult to gauge the exact issues without the Error or warnings attached.
Please have a look at the following code snippets for each of the codes, containing the corrections to the possible issues with the code.
DialogApp:
classdef DialogApp < matlab.apps.AppBase
properties (Access = private)
CallingApp % Description
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, mainapp, uT, lT, uH, lH)
app.CallingApp = mainapp;
app.uppertresholdEditField.Value = uT;
app.lowertresholdEditField.Value = lT;
app.upperhysteresisthresholdEditField.Value = uH;
app.lowerhysteresisthresholdEditField.Value = lH;
end
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
% Pass values to the main app using the CallingApp reference
app.CallingApp.get_adv_edg_data(...
app.uppertresholdEditField.Value, ...
app.lowertresholdEditField.Value, ...
app.upperhysteresisthresholdEditField.Value, ...
app.lowerhysteresisthresholdEditField.Value);
% Close the dialog
delete(app);
end
% Close request function: UIFigure
function AdvEdg_Closerequest(app, event)
% Delete the dialog box
delete(app);
end
end
end
MainApp:
classdef MainApp < matlab.apps.AppBase
properties (Access = private)
DialogApp
upT = 0;
loT = 0;
upH = 0;
loH = 0;
end
methods (Access = public)
function get_adv_edg_data(app, uT, lT, uH, lH)
% This method should be able to update the MainApp's properties
app.upT = uT;
app.loT = lT;
app.upH = uH;
app.loH = lH;
% You can include additional logic to update the UI here if needed
end
end
methods (Access = private)
% This method will be called when MainApp is created
function startupFcn(app)
% Create the dialog app, passing the MainApp instance and default values
app.DialogApp = DialogApp(app, app.upT, app.loT, app.upH, app.loH);
end
% Other methods for MainApp functionality follow here
end
end
The DialogApp needs to be initialized when creating it in the startupFcn. The Values of the MainApp are passed throught the reference of the get_adv_edg_data method in the DialogApp.
Additionally, you can also refer to the some of the documentations:
The following answers might also help:
Hope this helps!

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by