Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView for running D3 javascript is slow after reloading HTML.
Forum Updated to NodeBB v4.3 + New Features

QWebView for running D3 javascript is slow after reloading HTML.

Scheduled Pinned Locked Moved Solved Qt WebKit
13 Posts 2 Posters 4.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CLang
    wrote on last edited by CLang
    #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)

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CLang
      wrote on last edited by
      #13

      The issue seems to be in Qt5.5 - I compiled with 5.3 and the issue is gone.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Konstantin Tokarev
        wrote on last edited by
        #2

        Which version of QtWebKit are you using?
        Does problem reproduce if you remove cache settings?

        C 1 Reply Last reply
        0
        • C Offline
          C Offline
          CLang
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • K Konstantin Tokarev

            Which version of QtWebKit are you using?
            Does problem reproduce if you remove cache settings?

            C Offline
            C Offline
            CLang
            wrote on last edited by CLang
            #4

            @Konstantin-Tokarev

            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.

            K 1 Reply Last reply
            0
            • C CLang

              @Konstantin-Tokarev

              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.

              K Offline
              K Offline
              Konstantin Tokarev
              wrote on last edited by
              #5

              Yep, try without this line

              C 1 Reply Last reply
              0
              • K Konstantin Tokarev

                Yep, try without this line

                C Offline
                C Offline
                CLang
                wrote on last edited by CLang
                #6

                @Konstantin-Tokarev

                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.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Konstantin Tokarev
                  wrote on last edited by
                  #7

                  You should use qtwebkit from 5.212 branch, version coming with Qt 5.5 is obsolete

                  C 1 Reply Last reply
                  0
                  • K Konstantin Tokarev

                    You should use qtwebkit from 5.212 branch, version coming with Qt 5.5 is obsolete

                    C Offline
                    C Offline
                    CLang
                    wrote on last edited by
                    #8

                    @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?

                    K 1 Reply Last reply
                    0
                    • C CLang

                      @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?

                      K Offline
                      K Offline
                      Konstantin Tokarev
                      wrote on last edited by
                      #9

                      @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

                      C 1 Reply Last reply
                      0
                      • K Konstantin Tokarev

                        @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

                        C Offline
                        C Offline
                        CLang
                        wrote on last edited by
                        #10

                        @Konstantin-Tokarev

                        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?

                        K 1 Reply Last reply
                        0
                        • C CLang

                          @Konstantin-Tokarev

                          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?

                          K Offline
                          K Offline
                          Konstantin Tokarev
                          wrote on last edited by
                          #11

                          No, MSVC 2013 is not supported. You need MSVC >= 2015 or MinGW >= 4.9

                          C 1 Reply Last reply
                          0
                          • K Konstantin Tokarev

                            No, MSVC 2013 is not supported. You need MSVC >= 2015 or MinGW >= 4.9

                            C Offline
                            C Offline
                            CLang
                            wrote on last edited by
                            #12

                            @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'?

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              CLang
                              wrote on last edited by
                              #13

                              The issue seems to be in Qt5.5 - I compiled with 5.3 and the issue is gone.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved