Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. WebView access to HTTP Status Code

WebView access to HTTP Status Code

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 5.2k 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.
  • M Offline
    M Offline
    mbarclaygmail.com
    wrote on last edited by
    #1

    Hello,

    I'd like to know when my WebView gets a 404 or otherwise fails to load a web page. If the URL is malformed, I can use onLoadFailed, but I don't know how to catch a 404 and respond in QML. Is this possible?

    @
    import Qt 4.7
    import QtWebKit 1.0

    WebView {
    width: 640
    height: 480
    url: "http://www.google.com/page/does/not/exist.html"

    onLoadFailed: {
        console.log("Page failed to load: " + url)
    }
    

    }
    @
    Thanks,
    Matt

    1 Reply Last reply
    0
    • N Offline
      N Offline
      ngocketit
      wrote on last edited by
      #2

      WebView is quite limited and I'm afraid you can't do that without using any tricks. Here is one of the tricks: using XMLHttpRequest to request the same url inside onLoadFailed and catch the status code, e.g, something like this:
      @
      onLoadFailed: {
      var xhr = new XMLHttpRequest();
      xhr.onreadystatechange = function() {
      if (xhr.status == 404) { print('URL not found: ' + url) }
      }
      xhr.open("HEAD", url, true);
      xhr.send(null);
      }
      @

      Cheers,
      Phi

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrasser
        wrote on last edited by
        #3

        Hi,

        I'd recommend adding a suggestion in the bug tracker for this -- so hopefully it will become easier to handle in future versions.

        Regards,
        Michael

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbarclaygmail.com
          wrote on last edited by
          #4

          I will give that XMLHttpRequest a try. Thanks for the suggestion!

          "http://bugreports.qt.nokia.com/browse/QTBUG-17405":http://bugreports.qt.nokia.com/browse/QTBUG-17405

          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