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



  • 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?



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



  • 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.



  • 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 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! ;-)



  • [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?



  • [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? :-)



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



  • [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! :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.