Using the WebView module with C++ and Qt Widgets

· by Kaloyan Chehlarski · 3 min read · original post ↗

·

For a long time, developers of Qt-based C++ applications have only had one option for embedding web content: Qt WebEngine. And while it offers a large API with many useful features, the module has its downsides, since it can consume a lot of system resources and increase binary size. For QML users, we’ve had an alternative in the Qt WebView module, but that API had never been exposed to C++ until now.

With Qt 6.11, we released a C++ API for Qt WebView under Technology Preview status. This article is intended to give a brief overview of the usage of the new C++ API and describe the differences with its QML counterpart. While we’ve tried to keep it as close to the existing QML API as possible, some changes have been made, and we’re looking for feedback on its implementation from developers interested in using it.

But first, a brief overview: both WebEngine and WebView are APIs used to embed web content inside your application. But while Qt WebEngine directly embeds a Chromium runtime inside your application, Qt WebView instead acts as a light wrapper around the system-provided web libraries (where those exist; otherwise it wraps WebEngine). This can be quite useful, as it makes your application lighter on resources and ensures you don’t need to worry about regularly updating for security fixes; the operating system will always provide you with the latest runtime. The full list of our supported platforms is as follows:

Windows Linux macOS iOS Android WebAssembly
System Backend Microsoft Edge WebView2 N/A WkWebView WkWebView Android WebView