I am using a QWebView
to display plots using javascript and D3. There is a combobox to select different datasets. Each time a new dataset is selected, some calculations are done, then the javascript is reinitialized with the new data and set as an html string. Then the QWebview
is reset using QWebView::setHtml()
.
If I change the combobox value a few times, the plots load exponentially slower each time until it eventually freezes. Sometimes it will eventually load and sometimes not.
(I'm not sure the javascript is relevant - it is not my area of expertise so I haven't taken the time to understand it yet. I'm hoping the problem can be resolved with Qt code - but let me know and I can include that)
From the QWebView documentation: "The html is loaded immediately; external objects are loaded asynchronously."
My guess is that the javascript continues to execute in the background and it doesn't stop when the html is updated and reloaded. Is there a way to stop this?
The code for initializing and updating are as follows:
dataView::dataView(QWidget* parent) : QWidget(parent)
{
init();
}
void dataView::init()
{
webView = new QWebView();
// Need path to exe as this is where the local copies of the js files are.
QUrl path = webView->url();
path.setUrl(QCoreApplication::applicationDirPath());
m_jsPath = path.toString().toStdString();
// Initialise the html string
htmlText=""
webSetting = webView->settings();
// Maybe doing nothing-----------------------
webSetting->setObjectCacheCapacities(0, 0, 0);
webSetting->setMaximumPagesInCache(1);
//--------------------------------------------
QPointer<QVBoxLayout> mainLayout = new QVBoxLayout();
mainLayout->addWidget(webView);
setLayout(mainLayout);
}
void dataview::updatePlot()
{
//Get new value and do some calculations
// Update html string with new data
std::string htmlString = "[new javascript]";
webView->setHtml(QString::fromLocal8bit(htmlString.c_str()));
}