How to find listeners attached to an object

28 ビュー (過去 30 日間)
Daniel 2014 年 8 月 14 日
コメント済み: DNF 2021 年 4 月 27 日
I thought this would be a trivial task, but I cannot find the way to do this. Given an object in your workspace, is there an easy way to get handles to all the listeners that have been defined on this object?
cheers, Daniel
  5 件のコメント
Adam Danz
Adam Danz 2019 年 11 月 15 日
編集済み: Adam Danz 2019 年 11 月 15 日
I wish there were a way to h=findall('listeners') or h=findall(obj,'listeners') or something like that because some listeners are created by functions that do not return object handles and I don't know of any other way to get the listener handles (although I've only searched briefly).
To add context to my previous comment that brought this 5+ year thread back to life, I am (was; partially gave up) trying to troubleshoot this problem:


回答 (2 件)

Harry Dymond
Harry Dymond 2020 年 7 月 3 日
Found the answer on StackOverflow: any object with listeners attached will have an undocumented property .AutoListeners__, which is a cell array of listener handles. The cell array does not appear to get "pruned" if listeners are deleted, so .AutoListeners__{x} could contain a handle to a deleted listener. If the object has never had listeners created for any of its properties, .AutoListeners__ will not exist.
  2 件のコメント
DNF 2021 年 4 月 27 日
As far as I can tell this does not return all listeners. Listeners to some undocumented events do not show up. If you attach a listener to a window for its WindowMouseMotion event, then you cannot find that in the .AutoListeners__ array.


Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
Can't you save your listeners when created like this? :
handles.listener1 = addlistener(...);
handles.listener2 = addlistener(...);
Or that wont work for you?
  2 件のコメント
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
No i couldn't find anything like that either.



Find more on Events in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by