Skip to content

addlistener

Subscribe a callback to an event of a handle object.

hl = addlistener(Hsource, EventName, callback)
hl = addlistener(Hsource, PropName, EventName, callback)

Attaches callback (a function handle) to the named event EventName on the handle object Hsource. The returned listener handle hl controls the subscription — let it go out of scope (or call delete(hl)) to unsubscribe.

The four-argument form attaches a property-change listener: EventName is one of 'PreSet', 'PostSet', 'PreGet', 'PostGet'.

hl = addlistener(obj, 'StateChanged', @(src,evt) disp('changed'));
  • notify — Trigger an event on a handle object.
  • events — List the events declared by a class.