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. QWebView won't load file from qrc resource
Forum Updated to NodeBB v4.3 + New Features

QWebView won't load file from qrc resource

Scheduled Pinned Locked Moved Solved Qt WebKit
16 Posts 6 Posters 16.2k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    andreyc
    wrote on last edited by
    #7

    I looked at QUrl source code.
    It does not support qrc: prefix.
    A solution could be to copy index.html from the resource to a temporary file and then use QUrl::fromLocalFile("file://temp_path/index.html");

    1 Reply Last reply
    0
    • E Offline
      E Offline
      elkvis
      wrote on last edited by
      #8

      I wouldn't really consider that a solution. The web view has to load additional resources (css, js, images), based on the content of the html, and I'd have to literally copy everything to the temp folder. Once this project starts to get big, that's simply not an option.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #9

        I agree with you. It is not convenient. But I don't see the other way.

        I see two issues with putting all html related files as the resources:

        When you put all html, js, etc files in the executable file as the resources, how are you going to manage the links inside these html, js, etc files?

        If you will put a lot of resources in the executable file it will make the file big and relatively slow to load.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elkvis
          wrote on last edited by
          #10

          can you suggest alternatives, so that the content of my app isn't just sitting there on the user's computer to manipulate as they please?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #11

            I think Qt assistant maybe a good example. Take a look on how they provide and show bunch of html files.

            Or something simple like this

            • Extract all files to OS dependent cache directory on first run or after installation
              @
              QString cacheDir =
              QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
              @

            • Load the files from the cache directory

            • Provide checksum for the files if you need to protect an app from loading the modified files.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              elkvis
              wrote on last edited by
              #12

              Thanks for the suggestion. I used exactly what you suggested (except TempLocation instead of CacheLocation), and recursively copied the contents of the resources to the destination folder. Everything works, and files are deleted automatically on program exit on my target platform (linux).

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #13

                Glad it works for you.
                Could you please prepend "[SOLVED]" to the title of your post. It will help other good people to find your solution.

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  olgii10
                  wrote on last edited by
                  #14

                  If you're reading from a .qrc resource file you have to run qmake ("Build->Run qmake" in Qt Creator) before it will be available.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #15
                    This post is deleted!
                    1 Reply Last reply
                    1
                    • D Offline
                      D Offline
                      Donald Duck
                      wrote on last edited by
                      #16

                      For me, using the qrc:/ protocol (qrc:/html/index.html) along with cleaning the project and running qmake worked. But it didn't work by simply using :/html/index.html or before cleaning the project and running qmake.

                      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