Receiving a message from an owned object that is not a gui element


This is a very basic question, but I’m inexperienced and can’t work out what to search for.

I have a instance of a class that does most of the work in my application. It is owned by my MainContentComponent, but (so far) does not itself inherit from any juce classes.

It needs to send a simple message (just a ping really) to the MainContentComponent when an event occurs that is not user generated, so the MainContentComponent can update the gui. rather like a button and listener setup.

What is the simplest lightest way to do this?


You could pass a reference to your MainContentComponent to the owned class via its constructor and then when you need to update the GUI call the update function on this reference.



…indeed the easiest way to do. But because you mention button/listener:
the generic version of this would be ChangeBroadcaster and ChangeListener, if you prefer it plug- and unpluggable.
And the changeMessages will be asynchronous and coalesced (if you want).


thanks! that pointed me in the right direction.

I have been passing pointers to arrays between classes like that but passing a pointer to a whole class on another thread was rather more complex. I had to look up how to do forward declaration and also the message manager lock - but it now works!

I hope I remember how next time…