Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QWebView unable to load a page when the content-type isn't set

    Qt WebKit
    3
    8
    5981
    Loading More Posts
    • 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.
    • R
      rmccarthy last edited by

      Hi there,

      I'm using a custom web server with a PyQt4 application that embeds a QWebView as a web browser.

      I've noticed that certain pages won't load and, by trial and error, found that if I force my web server to always set the content-type to 'text/html' I can get these pages to load.

      If I try to load these pages in another web browser (Chrome, Safari or Firefox) they work fine without any alterations to the server.

      So, my questions are:-

      1. Is there a way to set a default content-type for a QWebView?
      2. Is it possible to put the QtWebKit module into a debug/logging mode to see if it outputs anything when one of these pages fail to load?
      3. Is there another possible solution for this problem other that changing the server?

      Thanks in advance,
      Rory

      1 Reply Last reply Reply Quote 0
      • D
        dangelog last edited by

        Otherwise what happens? Did you investigate which content-types make QtWebkit happy? Is the QWebPage::unsupportedContent fired?

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply Reply Quote 0
        • B
          benjamin.poulain last edited by

          Those are limitation of the network stack. It does not do content type detection if the server does not report a valid type.

          If you are on Linux, you can try using KIO, I think it does content type detection.

          If you are just using the view with you server, you can simply subclass QNetworkAccessManager and force the type yourself.

          1 Reply Last reply Reply Quote 0
          • R
            rmccarthy last edited by

            Thanks for the replies guys.

            @peppe
            Neither unsupportedContent or loadStarted are firing which is confusing. Does this mean it supports the content, but refuses to load it..?

            @Benjamin Poulain
            I think subclassing QNetworkAccessManager will do the trick, I'll give that a shot.

            1 Reply Last reply Reply Quote 0
            • R
              rmccarthy last edited by

              I'm still unable to find a solution to this issue.

              @peppe
              unsupportedContent is actually firing, I had not setForwardUnsupportedContent to True. I've dumped the QNetworkRequest and QNetworkReply from QNetworkAccessManager.createRequest in an effort to understand what's going on:-

              createRequest: request - url - http://localhost:8002/Test/
              createRequest: request - raw header - User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) Qt/4.7.2 Safari/533.3
              createRequest: request - raw header - Accept application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5

              createRequest: reply - url - http://localhost:8002/Test/
              createRequest: reply - attribute - QNetworkRequest.ConnectionEncryptedAttribute - false

              When unsupportedContent fires I dump the reply again:-

              onUnsupportedContent: reply - url - http://localhost:8002/Test/
              onUnsupportedContent: reply - attribute - QNetworkRequest.HttpStatusCodeAttribute - 200
              onUnsupportedContent: reply - attribute - QNetworkRequest.HttpReasonPhraseAttribute - OK
              onUnsupportedContent: reply - attribute - QNetworkRequest.ConnectionEncryptedAttribute - false
              onUnsupportedContent: reply - attribute - QNetworkRequest.HttpPipeliningWasUsedAttribute - false
              onUnsupportedContent: reply - raw header - Connection keep-alive
              onUnsupportedContent: reply - raw header - Transfer-Encoding chunked

              I'm inexperienced with this kind of thing, but I can't see anything wrong with this output. Am I missing something?

              @Benjamin Poulain
              I've not been able to force the content type by subclassing QNetworkAccessManager. Do you have experience doing this? If so, how did you do it?

              1 Reply Last reply Reply Quote 0
              • B
                benjamin.poulain last edited by

                Can't you wrap the QNetworkReply and change the headers?

                1 Reply Last reply Reply Quote 0
                • R
                  rmccarthy last edited by

                  Hi Benjamin,

                  Thanks for the quick reply!

                  If I try something like the following:-
                  reply.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, 'text/html')

                  I get the error message:-
                  RuntimeError: no access to protected functions or signals for objects not created from Python

                  Is this a limitation of PyQt?

                  Cheers,
                  Rory

                  1 Reply Last reply Reply Quote 0
                  • B
                    benjamin.poulain last edited by

                    Oh, I see. I was not aware python could not do that.
                    I guess a solution would be to load the page separately and use QWebFrame::setHtml() but that could get messy with the history, referer, etc.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post