Solved QWebView for running D3 javascript is slow after reloading HTML.
-
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)
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::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())); }
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); }
Hopefully I have included all the relative information code.
-
The issue seems to be in Qt5.5 - I compiled with 5.3 and the issue is gone.
-
Which version of QtWebKit are you using?
Does problem reproduce if you remove cache settings? -
This post is deleted! -
I am using Qt 5.5
I am unsure how to remove the cache settings but I will try that right now.
Edit: It appears that
webSetting->setObjectCacheCapacities(0, 0, 0);
should disable cache, so I have tried this.
-
Yep, try without this line
-
I have tried it with all combinations of the following settings (one, other one, both, none)
webSetting->setObjectCacheCapacities(0, 0, 0); webSetting->setMaximumPagesInCache(1);
I am going to try another Qt version and see if that has an effect.
-
You should use qtwebkit from 5.212 branch, version coming with Qt 5.5 is obsolete
-
@Konstantin-Tokarev said in QWebView for running D3 javascript is slow after reloading HTML.:
5.212
Thanks for the advice. Is 5.212 > 5.10?
And why such a weird version number? Should I download form git or is the qt installer going to have it?
-
@CLang For use with Qt 5.10, get binaries from http://download.qt.io/snapshots/ci/qtwebkit/5.212/latest/qtwebkit/
And why such a weird version number?
It isn't tied to particular Qt version, instead respective WebKitGTK's branch name is used as a basis
-
Thanks for all your help.
Does this mean I could download the source, compile it with cmake and msvc2013_64 and use it with qt5.5?
-
No, MSVC 2013 is not supported. You need MSVC >= 2015 or MinGW >= 4.9
-
@Konstantin-Tokarev I actually downgraded to 5.3 and the issue has resolved.
What's the best way to resolve this post? Reply to the initial post with the solution and change to 'solved'?
-
The issue seems to be in Qt5.5 - I compiled with 5.3 and the issue is gone.