Azzera filtri
Azzera filtri

Setting up a notifier and listener in two different apps

3 visualizzazioni (ultimi 30 giorni)
% 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

Risposta accettata

chrisw23
chrisw23 il 24 Ott 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

Più risposte (0)

Categorie

Scopri di più su Software Development Tools in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by