PDA

View Full Version : Is the 'okay' parameter of QWebView::loadFinished() ever false?



kerchen
22nd May 2009, 20:52
I'm using QWebView to display an HTML page that is local to my machine. My code looks something like this:



m_url = "file:///c:temp/foo.html";

connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished(bool)));
m_webView->load( QUrl(m_url) );

.
.
.

void MyWindow::onLoadFinished(bool okay)
{
if ( ! okay )
{
QString errorMsg( tr("<html><body>An error occurred while trying to load %1.</body></html>").arg(m_url) );
m_webView->setHtml(errorMsg);
}
}


The problem is that 'okay' seems to always be true, even when:

the file doesn't exist
the file contains bad HTML
the file contains no HTML


In a search of the Trolltech TaskTracker and googling, I didn't find any reports of this issue, so I'm thinking maybe there's something wrong with how I'm using QWebView. According to the docs, the boolean parameter of loadFinished() "will indicate whether the load was successful or any error occurred." Seems like at least one of the cases I listed above would elicit an error indication from loadFinished(), but that's not happening. Does anyone know if I'm doing something wrong or if this is just a bug in QWebView::loadFinished()?

wysota
23rd May 2009, 22:53
Based on the source code of WebKit I can tell you there are two cases where the signal will be emitted with a value of false.

kerchen
26th May 2009, 13:13
Hmm, FrameLoaderClientQt::dispatchDidFailLoad() and FrameLoaderClientQt::dispatchDidFailLoading() appear to be the only two places in the webkit source where the flag is set to false, but it doesn't appear that those functions are ever called (at least not within the webkit source). I guess I won't count on that flag being useful any time soon. :(

wysota
26th May 2009, 21:18
They are probably called somewhere in the webkit core. And even if not, it doesn't mean they won't be called tomorrow.

BjarneLaursen
28th April 2010, 09:50
I'm developing an embeddead app where page reloads is supposed to be completely invisible (if contens is unchanged, of cause).
To set the url I:
web_view->setUpdatesEnabled(false);
web_view->load(QUrl(NewUrl));

Then on the load
void MainWindow::finishLoading(bool ok)
{
web_view->setUpdatesEnabled(true);
}


I can tell you that ok is ideed false now and then, I not sure why. Apperently it is called soon after with true. So I problaly need to only enable update if ok is true.
Maybe its some specifik errorcode from the server. It does not appear to be a timeout as it comes quite fast.
You right that missing files or fucked up html still generates ok=true. I guess it must be some specific errorcode from the server.

I know, need to do some counting on the setUpdatesEnabled