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. Is there a method to load html without external resources?
Forum Updated to NodeBB v4.3 + New Features

Is there a method to load html without external resources?

Scheduled Pinned Locked Moved Qt WebKit
7 Posts 3 Posters 2.3k Views 1 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.
  • Q Offline
    Q Offline
    qqiq
    wrote on last edited by
    #1

    I got html reply from website using qNetworkAccessManager. while I want to take advantage of the webkit to parse the html element but I do not want to take more time and bandwidth to load more things like css or js or imgs. I saw the method setHtml() or setContent from QWebView or QWebFrame both load external resources async. Is there a method to load html without external resources that can parse the HTML element? Thanks!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      As you have seen it is possible to load HTML from a string inside a "QWebView":http://qt-project.org/doc/qt-5/qwebview.html using its method "setHtml":http://qt-project.org/doc/qt-5/qwebview.html#setHtml. If the HTML does not contain any external resources this method should load it immediately.

      http://anavi.org/

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qqiq
        wrote on last edited by
        #3

        Thanks for suggestion. I know the setHtml would load my HTML sync, but it also load external resources like css or js.
        One idea came out in my mind is to subclass the QNetworkAccessManager used by QWebView and overwrite the createRequest method to block all the request loaded automatically by QWebView, so that the QWebView can not access external resources. Is this the best way to do it or is there a lightweight way?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #4

          Another option that you might consider is to strip all links to external resources from the HTML before loading it inside the QWebView.

          http://anavi.org/

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qqiq
            wrote on last edited by
            #5

            That looks more complicated. I have deal with css, js, and embedded js.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              [quote author="qqiq" date="1390596214"]That looks more complicated. I have deal with css, js, and embedded js. [/quote]

              OK, it all depends on the exact case that you have so it is up to you :)

              http://anavi.org/

              1 Reply Last reply
              0
              • V Offline
                V Offline
                veveve
                wrote on last edited by
                #7

                You can rewrite QNetworkAccessManager::createRequest function to skip some urls, see: "http://code.google.com/p/simple-media-player/source/browse/trunk/MyPlayer/src/adblock.py?spec=svn15&r=15":http://code.google.com/p/simple-media-player/source/browse/trunk/MyPlayer/src/adblock.py?spec=svn15&r=15

                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