[Interest] QQmlEngine clearComponentCache() and qmldir singleton

Jérôme Godbout jerome at bodycad.com
Thu Jul 16 19:49:41 CEST 2015


Hi,
I have a weird behavior with resetting the QQuickView and some Qml script
declared singleton inside qmldir. The singleton seem to stop exist properly
at some point during resetting the QQuickView script:

void myClearCurrentScript()
{

qquick_view->setSource(QUrl());
QCoreApplication::processEvents();
qquick_view->engine()->clearComponentCache();
// or qquick_view->engine()->trimComponentCache();

}

I have a singleton with a Loader for the style Component for controls. This
allow us to assign the Controls style like this:
Button { style: StyleSingleton.styleLoaderItem.buttonStyle }

This work well when running the application for the first time and can
change the loader Component on the fly without problem. But when I call the
myClearCurrentScript() and run a new component that also use the singleton,
the binding to styleLoaderItem seem to be dead.

>TypeError: Cannot read property 'button' of undefined

The trimComponentCache version seem to generate some errors but the
singleton can recover from it and the style got apply eventually. When
doing the clearComponentCache, the style is lost in a weird way (ComboBox
got draw but not it's choice content, etc) and generate a tons of errors of
undefined.
If I inspect the singleton and loader after application restart everything
seem to be fine. Look like the Component or thing used by the singleton
stop existing for a small period of time.

What is happening to Qml Singleton from qmldir when we call
clearComponentCache() ? Is it because I use a Loader, the Loader Component
get cleared (this what I suspect, since the the loader and singelton still
accessible but not the item inside it)?

Is there a way to also delete the singleton or having Loader preserve
properly with the trimComponentCache?

Thanks,
Jerome
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150716/8afa4591/attachment.html>


More information about the Interest mailing list