Results 1 to 2 of 2

Thread: QWebView: QMimeDatabase mimeTypeForUrl always returns "application/octet-stream"

  1. #1
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWebView: QMimeDatabase mimeTypeForUrl always returns "application/octet-stream"

    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:

    Qt Code:
    1. connect(this, &QWebView::linkClicked, this, &BrowserView::onLinkClicked);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void BrowserView::onLinkClicked(const QUrl & url)
    2. {
    3. QMimeDatabase mime;
    4. qDebug() << "mime type" << mime.mimeTypeForUrl(url).name();
    5. ...
    6. }
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebView: QMimeDatabase mimeTypeForUrl always returns "application/octet-stream"

    You could try using QNetworkAccessManager::head() to get the MIME type (HTTP content type) from the webserver.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 19th September 2014, 07:23
  2. Replies: 3
    Last Post: 5th November 2013, 18:48
  3. Replies: 3
    Last Post: 25th August 2009, 13:03
  4. QLocale::system().name() returns "C" instead of "de"
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 14:59
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.