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);
connect(this, &QWebView::linkClicked, this, &BrowserView::onLinkClicked);
To copy to clipboard, switch view to plain text mode
void BrowserView
::onLinkClicked(const QUrl & url
) {
QMimeDatabase mime;
qDebug() << "mime type" << mime.mimeTypeForUrl(url).name();
...
}
void BrowserView::onLinkClicked(const QUrl & url)
{
QMimeDatabase mime;
qDebug() << "mime type" << mime.mimeTypeForUrl(url).name();
...
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks