Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Load an html file from a Qt Resource file
Forum Update on Monday, May 27th 2025

[SOLVED] Load an html file from a Qt Resource file

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 11.3k 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.
  • S Offline
    S Offline
    sfilippidis
    wrote on last edited by
    #1

    I have created a Qt Resource file with an html file. I want to load it and make it display in the standard web-browser. I use:

    @QDesktopServices::openUrl(QUrl("qrc:/prefix/filename.html"));@

    but it doesn't work!

    Please notice that for normal URLs, (http://...) it works like a charm!

    Any ideas?

    https://www.filippidis.name/

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bergo.torino
      wrote on last edited by
      #2

      Show your .qrc file, maybe you have wrong path (some typos).

      It's compiling - mostly I'm slacking off ;)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        This will never work.

        QDesktopServices::openUrl() usually calls the operating system's default application to open the URL. As qrc is not a standard scheme, there is no application that will handle it. Additionally, Firefox, Explorer or Safari would not even know how to get the data behind the qrc file :)

        You can set a custom handler, but that would be a QObject subclass within your application.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          Not only the qrc scheme is (usually) not associated with any application, but remember that resources are compiled inside your executable. How is a 3rd party program supposed to access them?

          A workaround could be copying the file from the resource to a temporary file/directory and then use QUrl::fromLocalFile + QDesktopServices::openUrl.

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sfilippidis
            wrote on last edited by
            #5

            [quote author="bergo.torino" date="1309816535"]Show your .qrc file, maybe you have wrong path (some typos). [/quote]

            The resource file is automatic created from Qt Creator, so I find it difficult to have typos! ;-)

            https://www.filippidis.name/

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sfilippidis
              wrote on last edited by
              #6

              [quote author="Volker" date="1309817761"]This will never work.

              QDesktopServices::openUrl() usually calls the operating system's default application to open the URL. As qrc is not a standard scheme, there is no application that will handle it. Additionally, Firefox, Explorer or Safari would not even know how to get the data behind the qrc file :)

              You can set a custom handler, but that would be a QObject subclass within your application.[/quote]

              I understand... Could I just display the resource to a QTextBrowser, or something like that?

              https://www.filippidis.name/

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sfilippidis
                wrote on last edited by
                #7

                [quote author="peppe" date="1309831855"]Not only the qrc scheme is (usually) not associated with any application, but remember that resources are compiled inside your executable. How is a 3rd party program supposed to access them?

                A workaround could be copying the file from the resource to a temporary file/directory and then use QUrl::fromLocalFile + QDesktopServices::openUrl.[/quote]

                Could you kindly provide some sample code for the workaround you provide? :-)

                https://www.filippidis.name/

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #8

                  Why not display your resource html page in a QWebView that way you get the full power of WebKit to help you.

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sfilippidis
                    wrote on last edited by
                    #9

                    [quote author="peppe" date="1309831855"]Not only the qrc scheme is (usually) not associated with any application, but remember that resources are compiled inside your executable. How is a 3rd party program supposed to access them?

                    A workaround could be copying the file from the resource to a temporary file/directory and then use QUrl::fromLocalFile + QDesktopServices::openUrl.[/quote]

                    Finally I followed a similar workaround, and solved the issue! :-)

                    https://www.filippidis.name/

                    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