PDA

View Full Version : QWebView: QMimeDatabase mimeTypeForUrl always returns "application/octet-stream"



alketi
29th April 2015, 19:17
I have a QWebView and am trying to determine the mime type of a clicked link, so I can hand-off the loading of a PDF, for example.

So, in my browser subclass, I handle a link click:


connect(this, &QWebView::linkClicked, this, &BrowserView::onLinkClicked);



void BrowserView::onLinkClicked(const QUrl & url)
{
QMimeDatabase mime;
qDebug() << "mime type" << mime.mimeTypeForUrl(url).name();
...
}


The problem is, the mime type always comes back as "application/octet-stream", which is the default if Qt can't parse the mime-type.

However, I'm clicking on links which are known PDF files. For example, any of the links here: https://www.google.com/?gws_rd=ssl#q=example+pdf

Isn't there a way to get the mime type from a URL for a known type, like a PDF?

anda_skoa
30th April 2015, 08:38
You could try using QNetworkAccessManager::head() to get the MIME type (HTTP content type) from the webserver.

Cheers,
_