Overview
TheZeal::Browser::WebBridge class provides a bridge for communication between C++ code and JavaScript running in documentation pages. It uses Qtâs WebChannel framework to expose C++ methods and properties to JavaScript, enabling documentation pages to interact with the Zeal application.
Header: src/libs/browser/webbridge.h
Inherits: QObject
Class Definition
Properties
AppVersion
QString
Access: Read-only, constant
JavaScript Usage:
Constructor
WebBridge()
parent- Parent QObject (optional)
Methods
openShortUrl()
https://go.zealdocs.org/l/.
Parameters:
key- Short URL key to append to the base URL
- Constructs full URL:
https://go.zealdocs.org/l/{key} - Opens in desktop browser via
QDesktopServices::openUrl()
triggerAction()
actionTriggered() signal which is connected to the main windowâs action handler.
Parameters:
action- Action identifier string
- Emits
actionTriggered(action)signal - Main window handles the action and performs the corresponding operation
Signals
actionTriggered()
triggerAction() is called from JavaScript.
Parameters:
action- Action identifier that was triggered
Qt WebChannel Integration
Registration
The WebBridge is registered with a QWebChannel and exposed to JavaScript through the channel:JavaScript Setup
Documentation pages must include the Qt WebChannel JavaScript library:Usage Examples
Complete JavaScript Integration
Using Promises for Asynchronous Calls
Qt WebChannel methods return promises in JavaScript:Reading Properties
C++ Application Integration
MainWindow Setup
From mainwindow.cpp:121:WebControl Integration
From webcontrol.cpp:82:Implementation Details
Source Files
- Header: src/libs/browser/webbridge.h
- Implementation: src/libs/browser/webbridge.cpp
Key Features
- Q_INVOKABLE Macro: Marks methods as accessible from JavaScript
- Q_PROPERTY Macro: Exposes C++ properties to JavaScript as object properties
- Signal/Slot Connection: Enables event-driven communication from JavaScript to C++
- QWebChannel Transport: Handles serialization and communication between JavaScript and C++
Best Practices
Error Handling
Asynchronous Nature
Property Access
See Also
- WebView - Widget that renders the documentation
- WebPage - Page class that hosts the WebChannel
- Qt WebChannel Documentation
- Qt WebChannel JavaScript API
- Core::Application - Provides application version information