Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. [SOLVED] Display HTML from QRC in WebEngineView

[SOLVED] Display HTML from QRC in WebEngineView

Scheduled Pinned Locked Moved QtWebEngine
7 Posts 3 Posters 6.0k 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.
  • N Offline
    N Offline
    Nathan H
    wrote on 10 Aug 2015, 18:23 last edited by Nathan H
    #1

    I would like to display HTML files (with associated JS and CSS) that get bundled with my application in QRC in a WebEngineView (I'd prefer to use QML, but if necessary I can use widgets). How can I do this? I've tried loading "qrc:/index.html" as the URL in both a QML and widgets based application, and in both cases the web engine assumes index.html is a domain and fails on the DNS lookup.

    Where am I going wrong here? Thanks. :)

    Be well

    --
    Nathaniel

    P 1 Reply Last reply 12 Aug 2015, 09:33
    0
    • N Nathan H
      10 Aug 2015, 18:23

      I would like to display HTML files (with associated JS and CSS) that get bundled with my application in QRC in a WebEngineView (I'd prefer to use QML, but if necessary I can use widgets). How can I do this? I've tried loading "qrc:/index.html" as the URL in both a QML and widgets based application, and in both cases the web engine assumes index.html is a domain and fails on the DNS lookup.

      Where am I going wrong here? Thanks. :)

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 12 Aug 2015, 09:33 last edited by
      #2

      Hi @Nathan-H,
      AFAIK it is still not supported as it just invokes the underlying platforms webview and it wont understand the Qt's Resource System. Instead you can read the HTML file from qrc on C++ side and pass it as a string to QML where you can use loadHtml to load it in web view.

      157

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nathan H
        wrote on 12 Aug 2015, 14:17 last edited by
        #3

        I've looked at using loadHTML, but the page I'm loading pulls in external resources like image, JS and CSS files. How do I load those when those files are also in QRC?

        Be well

        --
        Nathaniel

        P 1 Reply Last reply 13 Aug 2015, 05:46
        0
        • N Nathan H
          12 Aug 2015, 14:17

          I've looked at using loadHTML, but the page I'm loading pulls in external resources like image, JS and CSS files. How do I load those when those files are also in QRC?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 13 Aug 2015, 05:46 last edited by p3c0
          #4

          @Nathan-H AFAIK it will work. Try using qrc:/ before source files.
          P.S: Good news is loading HTML file from qrc now works in Qt 5.5.

          157

          N 1 Reply Last reply 14 Aug 2015, 14:45
          0
          • P p3c0
            13 Aug 2015, 05:46

            @Nathan-H AFAIK it will work. Try using qrc:/ before source files.
            P.S: Good news is loading HTML file from qrc now works in Qt 5.5.

            N Offline
            N Offline
            Nathan H
            wrote on 14 Aug 2015, 14:45 last edited by
            #5

            @p3c0 Is there any docs on that? I'm using 5.5, and it doesn't work...

            Be well

            --
            Nathaniel

            1 Reply Last reply
            0
            • W Offline
              W Offline
              WaltPurvis
              wrote on 14 Aug 2015, 18:35 last edited by
              #6

              Using a qrc:/ url definitely works. I routinely load css and js files into a WebEngineView with urls (inside the html) like "qrc:/blah.js" and setting the url of a WebEngineView to "qrc:/index.html" also works as expected. If it's not working for you, there's some other problem.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nathan H
                wrote on 14 Aug 2015, 20:23 last edited by
                #7

                OK, so I just tried it again and now it works. No idea what's different from earlier this week, but I'm glad it works now. :]

                Be well

                --
                Nathaniel

                1 Reply Last reply
                0

                7/7

                14 Aug 2015, 20:23

                • Login

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