Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to make QWebEngineView recognize qthelp URL scheme?



  • Hello everybody,

    I am trying to implement the help browser using QWebEngineView:

    class HelpBrowser : public QWebEngineView
    {
        public:
    
            HelpBrowser(QHelpEngine & help_engine, QWidget* parent);
    
    	void setUrl(const QUrl &url);
    
        private:
    
            QHelpEngine & helpEngine;
    
    };
    

    where

    void HelpBrowser::setUrl(const QUrl &url)
    {
        setHtml(helpEngine.fileData(url), url);
    }
    

    Loading the initial page as

    browser->setUrl(QUrl("qthelp://editor_help/help/index.html"));
    

    works, but the links are not working. When clicked, the error messages are printed in the Application Output:

    gvfs-open: qthelp://editor_help/help/file_formats.html: error opening location: The specified location is not supported
    

    Thank you in advance for any suggestions!

    Roni.


  • Moderators

    @roni219 That is because QWebEngineView doesnot understand what qthelp protocol is and thus tries to open it in external handler and thus the error.
    AFAIK assitant is the proper tool to open these files.
    Here is an example to open them at runtime.
    http://doc.qt.io/qt-5/qtassistant-remotecontrol-example.html

    Apart from that if you know the exact locations(local path) of these files QWebEngineView should be able open them.
    For eg. One of the Qt help files on my system:
    file:///opt/Qt5.7.0/Docs/Qt-5.7/qtcore/qobject.html

    Well atleast firefox opens them nicely(with css and stuff intact) using local path and so should QWebEngineView.



  • Thank you for reply, @p3c0 !

    I implemented Help window based on the example. The implementation used QTextBrowser (and so does Assistant). It suits my needs because the help content can be compressed in *.qhc and *.qch files, and deployed with the application. It turned out that QTextBrowser was not the best option for displaying HTML files.

    The dilemma:

    • QTextBrowser recognozes qthelp URL scheme but has limited support for HTML formatting

    • QWebEngineView displays HTML files nicely but does not recognize qthelp URLs

    I found suggestion that QWebEngineView can recognize the qthelp with QWebEngineUrlSchemeHandler, but the post does not explain how to do it.



  • Why do you need qthelp URLs? you can put your html files in a resource (.qrc) and they will be packed with the application. Any particular reason why you'd want *.qhc files?



  • No, i used qthelp only because of the example. In fact resources would be much simpler to deploy.

    • Does QWebEngineView support qrc URL scheme?

    • Will it know that the relative links in a "qrc://" HTML file are links to qrc files?



  • I just tried it, and the answer is "yes" to both questions.

    Thank you everybody for the help with this and the previous topic, especially @VRonin for suggesting QWebEngineView and qrc!


  • Qt Champions 2017

    @roni219 said in How to make QWebEngineView recognize qthelp URL scheme?:

    for suggesting QWebEngineView and qrc!

    Just be sure to compile your resources externally and load them at runtime, instead of compiling them into the application binary. Here's more info.

    Kind regards.



  • Thank you, @kshegunov, excellent advice! I will compile the resources externally.


Log in to reply