Setting up a notifier and listener in two different apps

4 vues (au cours des 30 derniers jours)
Scorp
Scorp le 24 Oct 2022
Commenté : Scorp le 25 Oct 2022
% I have a mainApp built in AppDesigner. It calls another app that displays data from main app in a number of different plots. I would like the
% user to click on one of these plots, in this case UIAxes and the coordinates are sent back to the mainApp. How do I setup a listener in the
% mainApp for a notifier that is fired in the display app? I have tried the setup below, but once the startupFcn is finished the instance of the
% listener is destroyed.
classdef mainApp
events
dataFromDisplayApp
end
methods (Access=private)
function startupFcn(app)
listener(app, 'dataFromDisplayApp', @doSomethingAsResultOfDataFromDisplayApp
end
function doSomethingAsResultOfDataFromDisplayApp (app)
disp('Done something')
end
function userWantsAPlotButtonPushed(app, event)
displayApp(mainApp)
end
classdef displayApp
methods (Access=private)
function startupFcn (app, caller)
app.myMainApp = caller;
end
function UIAxesButtonDown(app, event)
notify(app.mainApp, 'dataFromDisplayApp')
end

Réponse acceptée

chrisw23
chrisw23 le 24 Oct 2022
The "displayApp" has to provide the 'dataFromDisplay' event and the mainApp can add the listener.
app.myDisplayApp = displayApp(mainApp); % create the app object
app.liDispApp = addlistener(app.myDisplayApp,"dataFromDisplayApp",@app.dataFromDisplayApp_Callback); % register event

Plus de réponses (0)

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by