1

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()));
}

2 Answers2

1

There seems to be a problem with QWebkit 5.5. I compiled with Qt5.3 and the issue is not present.

0

I had a problem with this in QML and webview. I resolved it by placing this in the html. Granted it will only work if you have control of the HTML

<html>
<head>
    <meta http-equiv="refresh" content="12">
    <title> stuff </title>
</head>
<body>
    <p>body stuff</p>
</body>
</html>

the 12 = 12 seconds