Not possible to call triggerAsyncUpdate() from const functions


#1

Hi, getting the following compiler error when trying to call from const function:

]void juce::AsyncUpdater::triggerAsyncUpdate(void)’: cannot convert ‘this’ pointer from ‘const Parameters’ to 'juce::AsyncUpdater &'
the object has type qualifiers that are not compatible with the member function “juce::AsyncUpdater::triggerAsyncUpdate”

Thx


#2

Well no - triggering an update changes the internal state of the object, so we’d be lying if we marked it const!

There are many hacky workarounds you could use. E.g. const_cast<MyObject*> (this)->triggerAsyncUpdate.

But you should probably ask why your own method is marked const if it’s trying to change something that requires an update to be sent out.


#3

hi,yeah, I see what you mean, and now I understand the thinking I can just reorg some aspects of the call. the trigger async update is used to do some screen updates in response to a incoming MIDI message so the purpose is not really to update the state of the object, but to get back onto the UI thread for the screen updates and avoid using MessageManagerLocks…

thx


#4

Another way would be to add a private mutable member that inheritates from AsyncUpdater to prevent cheating with a const_cast