How to measure time taken for QML item to appear on the screen since it was loaded?

761 Views Asked by At

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.

2

There are 2 best solutions below

3
Mitch On

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. :)

1
Christian Stenzel On

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