1

I open website with QDeclarativeView and use JavaScript to load next pages in same view.

After each website loaded, my program occupy 20mb more of memory. How do i clean the cache or otherwise release the memory after new website is loaded?

I tried:

decView->engine()->rootContext()->setContextProperty("myEngine", decView->engine());

and then in qml

myEngine.clearComponentCache()

but i get

TypeError: Result of expression 'myEngine.clearComponentCache' [undefined] is not a function.

What i should do?

EDIT: here is what i got sofar:
aws.cpp

void Aws::openQMLWindowSlot(){
   QDeclarativeView *decView= new QDeclarativeView();
   decView->engine()->rootContext()->setContextProperty("myAws",this);
   decView->setSource(QUrl("qrc:/inc/firstqml.qml"));
   decView->show();
}

void Aws::clearCacheQMLSlot(){

//HERE I GOT PROBLEM
}

firstqml.qml

import QtQuick 1.1
import QtWebKit 1.0
WebView {

    id: webView
    objectName: "myWebView"
    url:"http://example.com"
    onLoadFinished: {myAws.clearCacheQMLSlot();}
}
2
  • There us gc() method in javascript, have you tried it? Dec 21, 2012 at 15:17
  • Yes, i tried webView.evaluateJavaScript("gc();"); and gc(), both with no results.
    – user891908
    Dec 21, 2012 at 15:28

1 Answer 1

1

There two reasons why your code doesn't work as intended. First, to be able to access slots and invokable methods of QObject descendants, you have to register them:

qmlRegisterType<QDeclarativeEngine>("MyApp", 1, 0, "QDeclarativeEngine");

And second, QDeclarativeEngine::clearComponentCache is neither a slot nor an invokable method, so it would still not work. It is simply impossible to call normal C++ methods from QML.

What you actually have to do is to implement an own QObject based class wrapping the call to QDeclarativeEngine::clearComponentCache in a slot, registering the class like above, set an instance of that class as an context property like you did with the declarative engine and finally call the slot from QML.

2
  • Thanks for answer.I'm setting 'this' with decView->engine()->rootContext()->setContextProperty("myAws",this); in same place i create decView, so all public slots are exposed to qml file but how i make a call to QDeclarativeEngine::clearComponentCachein that slot?
    – user891908
    Dec 21, 2012 at 20:48
  • 1
    Just store a pointer to the declarative view or to the engine in your class as a member variable and call the method on it.
    – sebasgo
    Dec 22, 2012 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.