Pages
API Documentation
On this page

KIO::FavIconRequestJob Class

FavIconRequestJob handles the retrieval of a favicon (either from the local cache or from the internet). More...

  • Header: #include <KIO/FavIconRequestJob>
  • CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
    target_link_libraries(mytarget PRIVATE KIOGui)
  • Inherits: KCompositeJob

List of all members, including inherited members

Public Functions

Detailed Description

For instance, the icon for http://www.google.com exists at http://www.google.com/favicon.ico This job will (the first time) download the favicon, and make it available as a local PNG for fast lookups afterwards.

Usage: Create a FavIconRequestJob, connect to result(KJob *), and from there use iconFile().

// Let's say we want to show the icon for QUrl m_url
KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(m_url);
connect(job, &KIO::FavIconRequestJob::result, this, [job, this](KJob *){
    if (!job->error()) {
        // show the icon using QIcon(job->iconFile())
    }
});

For a given HTTP URL, you can find out if a favicon is available by calling KIO::favIconForUrl() in KIOCore. It is however not necessary to check this first, FavIconRequestJob will do this first and emit result right away if a cached icon is available and not too old.

In Web Browsers, additional information exists: the HTML for a given page can specify something like <link rel="shortcut icon" href="another_favicon.ico" /> To handle this, call job->setIconUrl(iconUrl). (KParts-based web engines use the signal BrowserExtension::setIconUrl to call back into the web browser application, which should then call this). The signal urlIconChanged will be emitted once the icon has been downloaded.

The on-disk cache is shared between processes.

Member Function Documentation

[explicit] FavIconRequestJob::FavIconRequestJob(const QUrl &hostUrl, KIO::LoadType reload = KIO::NoReload, QObject *parent = nullptr)

FavIconRequestJob constructor

hostUrl The web page URL. We only use the scheme and host.

reload set this to reload to skip the cache and force a refresh of the favicon.

parent parent object

[override virtual noexcept] FavIconRequestJob::~FavIconRequestJob()

Destructor. You do not need to delete the job, it will delete automatically, unless you call setAutoDelete(false).

QUrl FavIconRequestJob::hostUrl() const

Returns the URL passed to the constructor

QString FavIconRequestJob::iconFile() const

Returns the full local path to the icon from the cache. Only call this in the slot connected to the result(KJob*) signal. Returns the path to the icon file

void FavIconRequestJob::setIconUrl(const QUrl &iconUrl)

setIconUrl allows to set, for a specific URL, a different icon URL than the default one for the host (http://host/favicon.ico)

This information is stored in the on-disk cache, so that other FavIconRequestJobs for this url and KIO::favIconForUrl will return the icon specified here.

iconUrl the URL to the icon, usually parsed from the HTML

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.