[Development] Calling a function at frame-rate before rendering

Gunnar Sletta gunnar.sletta at jolla.com
Wed May 14 18:31:11 CEST 2014

It depends on what your update state is...

If you want to tick rendering state (OpenGL and Scene Graph stuff) then you can call QQuickWindow::update() and make a direct connection to QQuickWindow::beforeRendering() to advance the state on the render thread just before the scene is drawn. 

If you have a QSGNode structure you want to update, call QQuickItem::update() and QQuickItem::updatePaintNode() will be called to synchronise your item state into the scene graph before the scene graph is rendered.

If you have GUI thread state, application logic and other stuff you can call QQuickItem::polish() and reimplemnt QQuickItem::updatePolish() which is called just before the QML tree is synced into the render thread.

If you have continuous animations use QAbstractAnimation and use the time you get in updateCurrentTime(). 


On 14 May 2014, at 16:53, raskolnikov at es.gnu.org wrote:

> Hi guys!
> So... I am working on a project where the data model is written in a
> functional style and uses a "epochal" approach to move it's state
> forward... the details would probably bore you but the important thing is
> that it requires a tick() function to be called to make an updated world
> state visible.
> This seems to be tricky in Qt and I haven't found the best approach yet...
> and I am starting to wonder if is even possible at all.
> Because following some discussions in this list it seems that animations
> are ticked at frame-rate, I tried deriving from QAbstractAnimation and
> tick updateCurrentTime(), however, that made the state lag one frame
> behind rendering, something quite visible when dragging an object (the Qt
> draggable would be updated automatically, but our data-model based stuff
> would lag one frame).
> Then I tried making an eventFilter() in which I do something like this:
>    if (event != MyTickEvent)
>        postEvent(MyTickEvent)
>    else
>        tick()
> I expected this to remove the lagging, but while it improves the
> situation, there are cases in which I can still see some lagging.
> Furthermore, this approach involves too much ticking, while ticking one
> per frame should be enough.
> So, am I missing something? Is there a general way to tick my state update
> before rendering?
> Thanks!
> JP
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

More information about the Development mailing list