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.
-
@roni219 That is because
QWebEngineView
doesnot understand whatqthelp
protocol is and thus tries to open it in external handler and thus the error.
AFAIKassitant
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.htmlApart 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.
-
-
@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.