[Interest] Using startTimer from a const member function?

René J.V. Bertin rjvbertin at gmail.com
Sat Sep 2 10:26:34 CEST 2017


I'm modifying a style (QtCurve) to not keep an animation timer running at all times but only when required. This means starting it from the Style::drawControl() method, which is a const function.

It was trivial to move the few Style member variables into a private class accessed via d-ptr, but the timer itself is based on QObject::startTimer() and evidently I cannot call that function from a const function.

For now I've worked around this by adding a q-ptr to the private subclass, and a `int startParentTimer(int d) { q->startTimer(d); }` function but that feels like a hack. (BTW, having to do this is why I didn't use mutual for the member variables.)

The other devs on the project don't seem to raise any eyebrowse over this but I'd still like to know if there isnt a more elegant way to achieve this that does not involve refactoring the whole code to use a dedicated animation class (or have the private subclass inherit QObject too)?


More information about the Interest mailing list