【发布时间】:2012-12-21 14:44:19
【问题描述】:
我使用 QDeclarativeView 打开网站并使用 JavaScript 在同一视图中加载下一页。
每个网站加载后,我的程序会多占用 20mb 内存。新网站加载后如何清理缓存或释放内存?
我试过了:
decView->engine()->rootContext()->setContextProperty("myEngine", decView->engine());
然后在qml中
myEngine.clearComponentCache()
但我明白了
TypeError:表达式“myEngine.clearComponentCache”[undefined] 的结果不是函数。
我该怎么办?
编辑:这是我到目前为止得到的:
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();}
}
【问题讨论】:
-
这里有我们
gc()javascript中的方法,你试过了吗? -
是的,我试过 webView.evaluateJavaScript("gc();");和 gc(),都没有结果。