1

How can I measure time passed since the moment I have changed source or sourceComponent property of QML Loader to the moment visual item actually appeared on the screen (got painted)?

Loader {
    id: _loader
    source: "MyVisualItem.qml"
}

I already tried using statusChanged and Component.onCompleted signals but neither is accurate enough - it is easy to see that actual time is significantly greater.

senx
  • 630
  • 9
  • 18

2 Answers2

1

According to the diagram in the documentation, frameSwapped() is your best bet:

enter image description here

You'll want to connect to that signal before setting source/sourceComponent, or directly afterwards. The first time it's called you can check the time it took to render it on screen. Don't forget to disconnect it afterwards. :)

Mitch
  • 23,716
  • 9
  • 83
  • 122
  • The problem is figuring out which one is the first frame that is indeed rendering the item. That's not so simple with the deferred rendering architecture behind Qt Quick 2 -- technically speaking, it could happen *any* amount of frames after the component says it's complete. – peppe Dec 16 '18 at 23:21
  • I am not sure if there's any API for an accurate knowledge of this information; maybe the QML profiling hooks can be used to know when the renderer is gathering information out of an item's scenegraph nodes, and _possibly_ estimate then that the next frame rendered is going to be the first one showing the item. (In other words, this requires knowledge on how the renderer works internally.) – peppe Dec 16 '18 at 23:23
  • And other similar ways come to mind, e.g. a custom C++ item building a QSGNode that has the preprocess flag set -- the renderer is going to call `QSGNode::preprocess` on it, thus one can again estimate that the next frame is going to be rendered including that node. – peppe Dec 16 '18 at 23:26
1

QML profiler should serve this issue (e.g. see here),

pure time measurement between source change and loading can be achieved by the loader item itself:

Loader.Ready - the QML source has been loaded
Loader.Loading - the QML source is currently being loaded

and loaded signal:

This signal is emitted when the status becomes Loader.Ready, or on successful initial load.    
The corresponding handler is onLoaded.

So measure time between source change occurence and onLoaded invocation

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I tried using onLoaded signal, but the results are too inaccurate - it shows 40-60ms when actual time was 1200-1500ms. I can surely use this numbers for comparison (i.e. to see whether particular change has worsened transition time or not) but I would prefer to have values that are as close to real time as possible – senx Dec 18 '18 at 09:27