QWebView not loading external resources
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-02-19T04:02:16Z
Indexed on
2010/03/29
18:03 UTC
Read the original article
Hit count: 592
Hi.
I'm working on a kiosk web browser using Qt and PyQt4. QWebView seems to work quite well except for one quirk.
If a URL fails to load for any reason, I want to redirect the user to a custom error page. I've done this using the loadFinished() signal to check the result, and change the URL to the custom page if necessary using QWebView.load(). However, any page I attempt to load here fails to pull in external resources like CSS or images.
Using QWebView.load() to set the initial page at startup seems to work fine, and clicking any link on the custom error page will result in the destination page loading fine. It's just the error page that doesn't work.
I'm really not sure where to go next. I've included the source for an app that will replicate the problem below. It takes a URL as a command line argument - a valid URL will display correctly, a bad URL (eg. DNS resolution fails) will redirect to Google, but with the logo missing.
import sys from PyQt4 import QtGui, QtCore, QtWebKit
class MyWebView(QtWebKit.QWebView):
def __init__(self, parent=None):
QtWebKit.QWebView.__init__(self, parent)
self.resize(800, 600)
self.load(QtCore.QUrl(sys.argv[1]))
self.connect(self, QtCore.SIGNAL('loadFinished(bool)'), self.checkLoadResult)
def checkLoadResult(self, result):
if (result == False):
self.load(QtCore.QUrl('http://google.com'))
app = QtGui.QApplication(sys.argv)
main = MyWebView()
main.show()
sys.exit(app.exec_())
If anyone could offer some advice it would be greatly appreciated.
© Stack Overflow or respective owner