Qt Forum

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

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

    General and Desktop
    5
    9
    10392
    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.
    • S
      sfilippidis last edited by

      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 Reply Quote 0
      • B
        bergo.torino last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

          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 Reply Quote 0
          • D
            dangelog last edited by

            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 Reply Quote 0
            • S
              sfilippidis last edited by

              [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 Reply Quote 0
              • S
                sfilippidis last edited by

                [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 Reply Quote 0
                • S
                  sfilippidis last edited by

                  [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 Reply Quote 0
                  • Z
                    ZapB last edited by

                    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 Reply Quote 0
                    • S
                      sfilippidis last edited by

                      [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 Reply Quote 0
                      • First post
                        Last post