Results 1 to 3 of 3

Thread: QWebView sometimes not loading external resources

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QWebView sometimes not loading external resources

    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.

    Qt Code:
    1. import sys
    2. from PyQt4 import QtGui, QtCore, QtWebKit
    3.  
    4. class MyWebView(QtWebKit.QWebView):
    5. def __init__(self, parent=None):
    6. QtWebKit.QWebView.__init__(self, parent)
    7. self.resize(800, 600)
    8. self.load(QtCore.QUrl(sys.argv[1]))
    9. self.connect(self, QtCore.SIGNAL('loadFinished(bool)'), self.checkLoadResult)
    10.  
    11. def checkLoadResult(self, result):
    12. if (result == False):
    13. self.load(QtCore.QUrl('http://google.com'))
    14.  
    15. app = QtGui.QApplication(sys.argv)
    16. main = MyWebView()
    17. main.show()
    18. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    If anyone could offer some advice it would be greatly appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView sometimes not loading external resources

    Maybe try redirecting not in loadFinished() but elsewhere. Try making the signal-slot connection queued, so that the slot is executed when the application is already back in the event loop. It's possible that loadFinished() is connected to some other slot which is interfering with what you are trying to do. Delaying your actions a bit might be enough to solve the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    complexgeek (6th June 2011)

  4. #3
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWebView sometimes not loading external resources

    Thanks wysota.

    After shelving this project for a number of reasons before picking it up again recently, your suggestion of using a queued connection worked perfectly!

    I switched from using PyQt to PySide, but the fix was as simple as:
    self.connect(self, QtCore.SIGNAL('loadFinished(bool)'), self.checkLoadResult, QtCore.Qt.QueuedConnection)

Similar Threads

  1. Is it possible to add QT resources to a DLL?
    By cboles in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2017, 00:12
  2. Replies: 16
    Last Post: 11th October 2009, 17:30
  3. Qt Resources
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 3rd October 2008, 16:30
  4. problem with resources
    By SuperSonik in forum Installation and Deployment
    Replies: 2
    Last Post: 15th February 2007, 10:58
  5. i need pyqt resources
    By slhtn in forum Newbie
    Replies: 2
    Last Post: 13th August 2006, 18:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.