Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-36656

Invalid resource encoding when referenced from webpage loaded with WebView.loadHtml()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.2.0, 5.2.1
    • Fix Version/s: None
    • Component/s: WebKit
    • Labels:
      None
    • Environment:
      Custom compiled Qt 5.2.0 and 5.2.1 on Mac OS X 10.9.1. I did not try to reproduce this problem on other platforms.

      Description

      When a webpage displayed by QML WebView has references to application resources (qrc:*), they work correctly only if the page is loaded using url property and not loadHtml() method.

      Sample program is attached and also available for convenient online browsing at https://gist.github.com/msiedlarek/8824547

      When loaded using url attribute, the webpage is displayed correctly and attached script is readable by the engine, as seen in the Inspector (success.png):

      But when the same HTML code is loaded using loadHtml method, the result is quite different (failure.png):

      I have tried tracing the problem in the QtWebKit source, but achieved nothing, probably knowing too little about its inner workings. It would be great if someone could shed some light on what's going on here.

      Edit 1

      Adding explicit charset="utf-8" to the script tag did it. Am I correct to assume that when the HTML is loaded from UTF-16 QString, the encoding of external scripts and stylesheet is expected to be UTF-16?

      This surprises me, because I used QWebView::setHtml() previously and it assumes (and mentions it in the docs) that external resources are UTF-8.

      So it's up to you to decide whether this is a bug or a lack of documentation.

        Attachments

        1. failure.png
          failure.png
          99 kB
        2. success.png
          success.png
          90 kB
        3. test.zip
          2 kB
        For Gerrit Dashboard: QTBUG-36656
        # Subject Branch Project Status CR V

          Activity

            People

            • Assignee:
              allan.jensen Allan Sandfeld Jensen
              Reporter:
              msiedlarek Mikołaj Siedlarek
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes