Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [SOLVED]check if url is an image

[SOLVED]check if url is an image

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    topix93
    wrote on last edited by
    #1

    is there any way to check, using the webview, if the loaded page is an image or not?.. for example if i open this link "image from google-search-image":http://phfg.fulcri.it/getImageBdf.asp?idArticolo=1841986&tipo=4&larghezza=200&altezza=200&key=2f5e1bd528f15f9899e1cf039cbe2d09 how can i check if it is an image?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mellitus
      wrote on last edited by
      #2

      Hi,

      i don't know if there is a feature for QWebView, but if you use QNetworkRequest for the given URL and then check the header data of the reply you will get the information, e.g:

      @void downloadFile(QUrl url)
      {
      ...
      QNetworkRequest req;
      req.setUrl(url);
      // Start request using a QNetworkAccessManager
      mpDownloadManager->get(req);
      ...
      }

      // Receiving function using:
      // connect(mpDownloadManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_fileDownloadFinished(QNetworkReply*)));
      void slot_fileDownloadFinished(QNetworkReply* pReply)
      {
      QString sFiletype = reply->header(QNetworkRequest::ContentTypeHeader).toString()
      ...
      }@

      sFiletype will contain something like:
      "image/jpeg"

      Hope that might help you.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        topix93
        wrote on last edited by
        #3

        i try your solution but for the link "image":http://phfg.fulcri.it/getImageBdf.asp?idArticolo=1841986&tipo=4&larghezza=200&altezza=200&key=2f5e1bd528f15f9899e1cf039cbe2d09, the file type "is text/html; charset=us-ascii" instead of "image/jpeg"

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mellitus
          wrote on last edited by
          #4

          Hi,

          I will check the code when i'm at home again....
          But using firefox you can check the header information on your own.
          Just open the url containing the image file in firefox. Then open tools->web developer->web console and press F5 to reload the page.
          Under 'network traffic' you will see a 'get' command:

          GET http://phfg.fulcri.it/getImageBdf.asp

          You can inspect the 'request' and the 'response' data at this point by clicking on the entry.

          best regards

          Mellitus

          1 Reply Last reply
          0
          • T Offline
            T Offline
            topix93
            wrote on last edited by
            #5

            i try again your example, now it works, i don't know what is changed.. sorry

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved