qt: use sampling based approach instead of event based approach to update high resolution time (SMPTE) widget
Currently, if Qt's event loop is not fast enough to consume the high resolution events, the events may backlog.
I initially tried to improve this in !5648 by clearing the unprocessed previous events waiting in the queue as soon as a new update event arrives (similar to Qt.callLater()
), essentially event compression. @chub suggested (!5648 (comment 450142)) to use sampling instead, which made sense to me.
QQuickText
might need polish to display the text properly, unfortunately QQuickWindow
does not signal before items are polished (unlike afterAnimating()
which is emitted after animating), this means that the updated text might be displayed properly with a one frame delay.
However, Qt 6.3 offers ensurePolished()
, which we can call immediately after updating the text. Normally this is not necessary, as adjusting the text calls schedules polish through polish()
, but that is asynchronous and can not help for that frame. The intention is to change the text for the frame as soon as possible so that the frame being prepared shows the latest sample.
I use afterAnimating()
of the quick window as the sampling point, as I expect it to be signalled for each frame. The advantage of it against beforeFrameBegin()
or beforeSynchronization()
is that it is emitted from the GUI thread. It is more idiomatic to call setText()
from the GUI thread.
Request review @chub.