Bug 29440 - [Qt] QWebSettings::iconForUrl() does not return a valid icon
Summary: [Qt] QWebSettings::iconForUrl() does not return a valid icon
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords: Qt
Depends on:
Blocks:
 
Reported: 2009-09-18 07:49 PDT by Tor Arne Vestbø
Modified: 2011-01-19 12:24 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Arne Vestbø 2009-09-18 07:49:10 PDT
This bug report originated from issue QTBUG-4323
<http://bugreports.qt.nokia.com/browse/QTBUG-4323>

--- Description ---

QWebSettings::iconForUrl() return a default icon or an invalid icon. Depending on the icon database, no icon is returned or the icon do not correspond to the website.

Here is an example to reproduce the problem, after closing the webview, the button should appear with the image of a penguin:


int main(int argc, char **argv){
  QApplication app(argc, argv);
  QWebView view;
  view.load(QUrl("http://www.linuxcertif.com/"));
  view.show();
  app.exec();
  QWebSettings::setIconDatabasePath("/tmp");
  QWebSettings::iconForUrl(QUrl("http://www.linuxcertif.com/"));
  QIcon icon = QWebSettings::iconForUrl(QUrl("http://www.linuxcertif.com/"));
  QPushButton button;
  button.setIcon(icon);
  button.show();
  return app.exec();
}
Comment 1 Kenneth Rohde Christiansen 2009-10-04 07:37:57 PDT
I believe Adam Treat did some initial patches for adding a QWebIconDatabase, but I don't know where that code is kept, nor if Adam is still willing to work on this.

Adam, can you comment on this?
Comment 2 Simon Hausmann 2009-11-22 09:36:43 PST
This is a bug in the provided testcase. When QtWebKit would try to load the icon via QWebView's initiation of the load process for the url there is no icon database path set, so the favourite icon is not set.

If you move the setIconDatabasePath("/tmp") line right after the construction of the QApplication, then the testcase works just fine.
Comment 3 Stephen 2011-01-19 12:24:35 PST
Simon, I believe there is still bug with QWebSettings::iconForURL for the QT 4.7.0 (32-bit, running on Windows). 

Here is the steps to produce the problem, 

1. Cache the icon by using QWebView to navigate to the target website first. Then close the application.

2. Restart the application, the first call to QWebSettings::iconForURL for the same URL will return null. 

3. Wait some time, make a second call to iconForURL, it will return a valid icon this time. 

4. If the two calls are made continuously without delay, both times will return null. 

So, to summarize, if an icon has been cached in a previous session, then the first call will return null. We have to wait some time and make a second call to get a valid icon. I believe a QWebView navigation also counts as a first time call. So, if you perform a navigation first and then make a call iconForURL in the same session, it will always succeed. 

The following code serves as a test case:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWebSettings::setIconDatabasePath(".");

    //run this for only once and then comment it out.
    QWebView view;
    view.load(QUrl("http://www.cnn.com/"));
    view.show();
    app.exec();

    QIcon icon=QWebSettings::iconForUrl(QUrl("http://www.cnn.com/"));
    QPushButton button;
    button.setIcon(icon);
    button.show();
    app.exec();
    icon=QWebSettings::iconForUrl(QUrl("http://www.cnn.com/"));
    button.setIcon(icon);
    button.show();
    return app.exec();
}

Please cache the icon with QWebView when you run it for the first time. After that, comment out the code block related to QWebView. Then run it again. You will see that the first button has no icon while the second button has the cnn icon. 

Can you guys investigate? Thanks a lot.