[webkit-qt] XHR on a remote server from a file: resource on Windows

Jeena Paradies jeenaparadies at gmail.com
Thu Mar 28 15:21:27 PDT 2013


I would like to write a Qt application which uses Webkit as its gui to
get data from a server and display it. I got it working unter Linux
and OS X without problems but under windows the XMLHttpRequest always
returns status 0 and I don't know why. Here is the pyqt code I use:

import sys, os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

app = QApplication(sys.argv)
web = QWebView()
web.page().settings().setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls,
True)
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'index.html'))
url = "file://localhost/" + path
web.load(QUrl(url))
web.show()
sys.exit(app.exec_())

and here is html HTML/JS I use to test it:

<!DOCTYPE html>
<title>TEST</title>
<h1>TEST</h1>
<div id="test"></div>
<script type="text/javascript">
    function t(text) { document.getElementById("test").innerHTML = text }

    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(this.status != 0)
            t(this.responseText)
        else
            t("Status is 0")
    }
    xhr.open("GET", "https://jeena.net/")
    xhr.send()
</script>

On Linux it opens a new Window with a WebKit view in it, loads html
local index.html file into it and renders it which shows the TEST
headline. After that it runs the XMLHttpRequest code to get a websites
content and set it with innerHTML into the prepared div.

On windows it loads and shows the title but then when it runs the xhr
code the status is always just 0 and it never changes, no matter what
I do.

As far as I understand LocalContentCanAccessRemoteUrls should make it
possible for the xhr to get that content from the remote website even
on windows, any idea why this is not working? I am using Qt version
4.9.6 on my windows machine and python v2.7.

I even tried it in C++ with the same result, on Linux and OS X it
works, on Windows it doesn't. Any idea how I could get it working?

 /Jeena


More information about the webkit-qt mailing list