QWebView does not load external resources

I am working on a kiosk browser using Qt and PyQt4. QWebView seems to work quite well, with the exception of one quirk.

If for some reason the URL is not loading, I want to redirect the user to the user error page. I did this using the loadFinished () signal to check the result, and if necessary change the URL to the user page using QWebView.load (). However, any page I'm trying to load here cannot use external resources such as CSS or images.

Using QWebView.load () to set the start page at startup seems to work fine, and clicking any link on the user error page will stop loading the landing page. This is just an error page that does not work.

I'm really not sure where to go next. I have included the source for the application that will replicate the problem below. It takes the URL as a command line argument - the correct URL will be displayed correctly, a bad URL (for example, DNS resolution failure) is redirected to Google, but with no logo.

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 someone can offer some advice, we will be very grateful.

+4
source share
1 answer

I donโ€™t know why this does not work, but something like

  def checkLoadResult(self, result): if (result == False): self.page().mainFrame().setHtml ( "<html><head><h1>Not Found</h1></head>\ <body><p> Search at <a href='http://google.com'> google </a>\ </p></body> </html>") 

does.

+1
source

Source: https://habr.com/ru/post/1301778/


All Articles