[Automotive] QmlLive: Is LiveNodeEngine::RecreateView mode really needed?

Martin Kampas martin.kampas at jolla.com
Mon Aug 8 11:17:25 CEST 2016


Hi Dominik,

Yes, due to the caching done by QQmlEngine, no change would be reflected in the view after just unsetting and setting the source again.

For this purpose there is the QQmlEngine::clearComponentCache() API available and it is already used on two places in LiveNodeEngine::recreateView() [1] (It's use here is redundant though, since the view/engine is already recreated.)

This API has been available already since Qt 4 [2] and since Qt 5.0 a potentially more usefull QQmlEngine::trimComponentCache() exists [3] which only clears unused entries. The effect of trimComponentCache() after clearing the source with view->setSource(QUrl()) is basically the same as of clearComponentCache() so it needs a bit more sophisticated approach to really profit from using it.

When the QML component being depeloped needs a specialized environment (context properties etc.), recreating view this way cannot be used at all.

Removing the RecreateView mode would allow for more strightforward code. Trying to eliminate memory leaks in LiveNodeEngine is not really easy currently.

I propose to

1) remove the RecreateView mode and only rely on clear/trimComponentCache() (check its effect here [4])
2) require to set QQmlEngine and make setting QQuickView optional (useless when the QML component instantiates QQuickWindow)
3) only after that fix memory leaks in LiveNodeEngine :)

If you agree I will contribute patches for this.

BR,
Martin

[1] https://codereview.qt-project.org/gitweb?p=qt-apps/qmllive.git;a=blob;f=src/livenodeengine.cpp;h=dbb5509;hb=HEAD#l246
[2] http://doc.qt.io/qt-4.8/qdeclarativeengine.html#clearComponentCache
[3] https://bugreports.qt.io/browse/QTBUG-25653
[4] http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qml/qml/qqmltypeloader.cpp?h=dev#n1958


More information about the Automotive mailing list