Question

I wish to get more information than just success = false in loadFinished (this is most often just a canceled load). From the documentation and other posts on this site, I gathered I should subclass QWebPage and override the extension() method to handle the ErrorPageExtension.

However, I'm not getting it to work, i.e., no matter what I try my extension method does not get called. I'm probably doing something really stupid but not seeing it. Basically my class looks like this:

class MyWebPage : public QWebPage
{
  Q_OBJECT

public:

  MyWebPage(QObject* parent = 0) : QWebPage(parent) {}  

  virtual bool extension(Extension extension,
                         const ExtensionOption* option = 0, 
                         ExtensionReturn* output = 0)
  {
    // blah
  }

  virtual bool supportsExtension(Extension extension)
  {
    // blah
  }  
};

The implementation of the methods is not the problem, I have a breakpoint there and it never gets called. I create an instance like

MyWebPage* page = new MyWebPage(this);

mUi.WebView->setPage(page);

I'm a bit uncertain about the life time of a QWebPage object in QWebView, but from my tests it seems the QWebPage always remains the same instance and simply loads new content. So I assumed I should simply give my page to the QWebView, I didn't see another way to make it use my derived class. But when loading bogus URLs, non-existing local files, or unsupported content, either via the WebView or directly via the mainframe of the page, I never get the call with ErrorPageExtension information.

Any help is appreciated. This is using Qt 4.8.2.

Was it helpful?

Solution

There is a bit mistake:

...
virtual bool supportsExtension(Extension extension) const // const!!!
{
    return QWebPage::ErrorPageExtension === extension;
}
...

You forgot to copy the const modifier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top